CSES - Aalto Competitive Programming 2024 - wk11 - Homework - Results
Submission details
Task:Exponentiation
Sender:Farah
Submission time:2024-11-21 02:30:00 +0200
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.04 sdetails
#20.04 sdetails
#30.04 sdetails

Code

MOD = 10**9 + 7

def modular_exponentiation(a, b, mod):
    if a == 0 and b == 0:
        return 1  # Special case: 0^0 = 1
    if a == 0:
        return 0  # 0^b = 0 for b > 0
    if b == 0:
        return 1  # a^0 = 1 for a > 0
    
    result = 1
    base = a % mod
    while b > 0:
        if b % 2 == 1:
            result = (result * base) % mod
        base = (base * base) % mod
        b //= 2
    return result

def main():
    import sys
    input = sys.stdin.read
    data = input().splitlines()
    
    n = int(data[0])
    results = []
    for i in range(1, n + 1):
        a, b = map(int, data[i].split())
        results.append(modular_exponentiation(a, b, MOD))
    
    sys.stdout.write('\n'.join(map(str, results)) + '\n')

Test details

Test 1

Verdict:

input
10201
0 0
0 1
0 2
0 3
...

correct output
1
0
0
0
0
...

user output
(empty)

Test 2

Verdict:

input
200000
129612095 411099530
241615980 487174929
60862511 511830781
758816482 982657640
...

correct output
276067146
838400234
148093882
546897305
467086232
...

user output
(empty)

Test 3

Verdict:

input
200000
692427692 536870911
252480658 536870911
505090334 536870911
27194853 536870911
...

correct output
940305728
707431813
917260341
908974199
375947818
...

user output
(empty)