| Task: | Finding inverse |
| Sender: | ileska |
| Submission time: | 2025-11-13 19:43:02 +0200 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | WRONG ANSWER | 0.04 s | details |
| #3 | ACCEPTED | 0.04 s | details |
| #4 | ACCEPTED | 0.04 s | details |
| #5 | WRONG ANSWER | 0.04 s | details |
| #6 | ACCEPTED | 0.04 s | details |
| #7 | ACCEPTED | 0.04 s | details |
| #8 | WRONG ANSWER | 0.04 s | details |
| #9 | ACCEPTED | 0.04 s | details |
| #10 | ACCEPTED | 0.30 s | details |
| #11 | WRONG ANSWER | 0.22 s | details |
| #12 | TIME LIMIT EXCEEDED | -- | details |
| #13 | TIME LIMIT EXCEEDED | -- | details |
| #14 | TIME LIMIT EXCEEDED | -- | details |
Code
def gcd(aa, bb):
while (aa != 0):
tmp = aa
aa = bb % aa
bb = tmp
return bb
def totient(nn):
result = 1
for ii in range(2, nn):
if (gcd(ii, nn) == 1):
result += 1
return result
def isPrime(nn):
if (nn % 2 == 0): return False
pp = 3
while (pp * pp < nn):
if (nn % pp == 0): return False
pp += 2
return True
def main(num, mod):
ret = 0
if isPrime(mod):
ret = pow(num, mod-2, mod)
else:
toti = totient(mod)
if toti == 2:
ret = -1
else:
ret = pow(num, toti - 1, mod)
return ret
if __name__ == "__main__":
num, mod = [int(aa) for aa in input().split(" ")]
ret = main(num, mod)
print(ret)Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 6 7 |
| correct output |
|---|
| 6 |
| user output |
|---|
| 6 |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 0 7 |
| correct output |
|---|
| -1 |
| user output |
|---|
| 0 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 5 78 |
| correct output |
|---|
| 47 |
| user output |
|---|
| 47 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 89 99 |
| correct output |
|---|
| 89 |
| user output |
|---|
| 89 |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 0 61 |
| correct output |
|---|
| -1 |
| user output |
|---|
| 0 |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 897 947 |
| correct output |
|---|
| 625 |
| user output |
|---|
| 625 |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 419 538 |
| correct output |
|---|
| 217 |
| user output |
|---|
| 217 |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 32 938 |
| correct output |
|---|
| -1 |
| user output |
|---|
| 44 |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 184120 505187 |
| correct output |
|---|
| 438779 |
| user output |
|---|
| 438779 |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 264601 885661 |
| correct output |
|---|
| 360221 |
| user output |
|---|
| 360221 |
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 40310 590135 |
| correct output |
|---|
| -1 |
| user output |
|---|
| 162465 |
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) |
