CSES - Aalto Competitive Programming 2024 - wk11 - Homework - Results
Submission details
Task:Finding inverse
Sender:Niilo
Submission time:2024-11-14 09:01:40 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#30.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#70.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#100.00 sdetails
#11ACCEPTED0.00 sdetails
#120.00 sdetails
#130.00 sdetails
#14ACCEPTED0.00 sdetails

Code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i=a;i<(b);++i)
#define all(x) begin(x),end(x)
#define sz(x) int((x).size())
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using ld = long double;

int M = 1e9+7;

int mpow(ll a, ll p) {
  ll r = 1;
  while (p != 0) {
    if (p & 1) {
      r *= a; r %= M;
    }
    a *= a; a %= M;
    p >>= 1;
  }
  return r;
}

int main() {
  int a;
  cin >> a >> M;
  int r = mpow(a,M-2);
  if (ll(a) * r % M != 1) cout << "-1\n";
  else cout << r << '\n';
}

Test details

Test 1

Verdict: ACCEPTED

input
6 7

correct output
6

user output
6

Test 2

Verdict: ACCEPTED

input
0 7

correct output
-1

user output
-1

Test 3

Verdict:

input
5 78

correct output
47

user output
-1

Test 4

Verdict: ACCEPTED

input
89 99

correct output
89

user output
89

Test 5

Verdict: ACCEPTED

input
0 61

correct output
-1

user output
-1

Test 6

Verdict: ACCEPTED

input
897 947

correct output
625

user output
625

Test 7

Verdict:

input
419 538

correct output
217

user output
-1

Test 8

Verdict: ACCEPTED

input
32 938

correct output
-1

user output
-1

Test 9

Verdict: ACCEPTED

input
184120 505187

correct output
438779

user output
438779

Test 10

Verdict:

input
264601 885661

correct output
360221

user output
-1

Test 11

Verdict: ACCEPTED

input
40310 590135

correct output
-1

user output
-1

Test 12

Verdict:

input
202254499 577081420

correct output
128866679

user output
-1

Test 13

Verdict:

input
539836073 888851205

correct output
797044652

user output
-1

Test 14

Verdict: ACCEPTED

input
697847215 756971670

correct output
-1

user output
-1