Task: | Finding inverse |
Sender: | Rasse |
Submission time: | 2024-11-14 14:00:00 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | TIME LIMIT EXCEEDED | -- | details |
#2 | WRONG ANSWER | 0.00 s | details |
#3 | WRONG ANSWER | 0.00 s | details |
#4 | WRONG ANSWER | 0.02 s | details |
#5 | WRONG ANSWER | 0.00 s | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | WRONG ANSWER | 0.08 s | details |
#8 | ACCEPTED | 0.01 s | details |
#9 | TIME LIMIT EXCEEDED | -- | details |
#10 | TIME LIMIT EXCEEDED | -- | details |
#11 | TIME LIMIT EXCEEDED | -- | details |
#12 | TIME LIMIT EXCEEDED | -- | details |
#13 | TIME LIMIT EXCEEDED | -- | details |
#14 | TIME LIMIT EXCEEDED | -- | details |
Code
#include <iostream> #include <vector> #include <array> #include <string> #include <algorithm> #include <numeric> #include <unordered_map> #include <unordered_set> #include <queue> #include <climits> #include <cmath> #include <functional> #include <type_traits> #include <fstream> #include <bitset> #include <complex> #include <iomanip> #define int long long using namespace std; #define cross(x, y) (((x)*conj(y)).imag()) #define sign(v) ((0 < (v)) - ((v) < 0)) int p(int a, int b, int m) { if (b == 0) return 1; else if (b % 2 == 0) { int r = p(a, b/2, m); return (r*r) % m; } else return (p(a, b-1, m)*a) % m; } int gdc(int a, int b) { if (b == 0) return a; return gdc(b, a%b); } void solve() { int a, m; cin >> a >> m; if (gdc(a, m) != 1) { cout << -1; return; } unordered_map<int, int> factors; int num = m; int top = sqrt(num); for (int i = 2; i <= top && i < num; i++) { while (num % i == 0) { factors[i]++; num /= i; } } if (num > 1) factors[num]++; // Calc phi int phi = 1; for (auto kv : factors) phi *= p(kv.first, kv.second-1, m) * (kv.first - 1); cout << p(a, phi-1, m) << '\n'; } signed main() { ios::sync_with_stdio(0); cout.precision(25); //setprecision(10); //cin.tie(0); int t = 1; cin >> t; //ifstream f("testcase.txt"); //cin.rdbuf(f.rdbuf()); for (int i = 0; i < t; i++) { solve(); cout.flush(); } }
Test details
Test 1
Verdict: TIME LIMIT EXCEEDED
input |
---|
6 7 |
correct output |
---|
6 |
user output |
---|
(empty) |
Test 2
Verdict: WRONG ANSWER
input |
---|
0 7 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 3
Verdict: WRONG ANSWER
input |
---|
5 78 |
correct output |
---|
47 |
user output |
---|
-1-19511203817901 -19511203817901 -19511203817901 -19511203817901 |
Test 4
Verdict: WRONG ANSWER
input |
---|
89 99 |
correct output |
---|
89 |
user output |
---|
1 -19511203817901 -19511203817901 -19511203817901 -19511203817901 ... Truncated |
Test 5
Verdict: WRONG ANSWER
input |
---|
0 61 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
897 947 |
correct output |
---|
625 |
user output |
---|
(empty) |
Test 7
Verdict: WRONG ANSWER
input |
---|
419 538 |
correct output |
---|
217 |
user output |
---|
-1-19511203817901 -19511203817901 -19511203817901 -19511203817901 -19511203817901 ... Truncated |
Test 8
Verdict: ACCEPTED
input |
---|
32 938 |
correct output |
---|
-1 |
user output |
---|
-1-19511203817901 -19511203817901 -19511203817901 -19511203817901 -19511203817901 ... Truncated |
Test 9
Verdict: TIME LIMIT EXCEEDED
input |
---|
184120 505187 |
correct output |
---|
438779 |
user output |
---|
(empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
input |
---|
264601 885661 |
correct output |
---|
360221 |
user output |
---|
(empty) |
Test 11
Verdict: TIME LIMIT EXCEEDED
input |
---|
40310 590135 |
correct output |
---|
-1 |
user output |
---|
(empty) |
Test 12
Verdict: TIME LIMIT EXCEEDED
input |
---|
202254499 577081420 |
correct output |
---|
128866679 |
user output |
---|
(empty) |
Test 13
Verdict: TIME LIMIT EXCEEDED
input |
---|
539836073 888851205 |
correct output |
---|
797044652 |
user output |
---|
(empty) |
Test 14
Verdict: TIME LIMIT EXCEEDED
input |
---|
697847215 756971670 |
correct output |
---|
-1 |
user output |
---|
(empty) |