Task: | Exponentiation |
Sender: | joaquimballester |
Submission time: | 2024-11-20 12:22:43 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | ACCEPTED | 0.52 s | details |
#3 | ACCEPTED | 0.51 s | details |
Code
#include <iostream> using namespace std; const int MOD = 1e9 + 7; long long mod_exp(long long a, long long b, int mod) { long long result = 1; a %= mod; while (b > 0) { if (b % 2 == 1) { result = (result * a) % mod; } a = (a * a) % mod; b /= 2; } return result; } int main() { int n; cin >> n; while (n--) { long long a, b; cin >> a >> b; if (a == 0 && b == 0) { cout << 1 << '\n'; } else { cout << mod_exp(a, b, MOD) << '\n'; } } return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
10201 0 0 0 1 0 2 0 3 ... |
correct output |
---|
1 0 0 0 0 ... |
user output |
---|
1 0 0 0 0 ... Truncated |
Test 2
Verdict: ACCEPTED
input |
---|
200000 129612095 411099530 241615980 487174929 60862511 511830781 758816482 982657640 ... |
correct output |
---|
276067146 838400234 148093882 546897305 467086232 ... |
user output |
---|
276067146 838400234 148093882 546897305 467086232 ... Truncated |
Test 3
Verdict: ACCEPTED
input |
---|
200000 692427692 536870911 252480658 536870911 505090334 536870911 27194853 536870911 ... |
correct output |
---|
940305728 707431813 917260341 908974199 375947818 ... |
user output |
---|
940305728 707431813 917260341 908974199 375947818 ... Truncated |