Task: | Exponentiation |
Sender: | aalto2024k_007 |
Submission time: | 2024-11-15 10:13:21 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | ACCEPTED | 0.54 s | details |
#3 | ACCEPTED | 0.54 s | details |
Compiler report
input/code.cpp: In function 'long long unsigned int fastpow(long long unsigned int, long long unsigned int)': input/code.cpp:19:15: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses] 19 | if (n & 1 == 1) return x * fastpow(x, n-1) % MOD; | ~~^~~~
Code
#include <bits/stdc++.h> using namespace std; #define debug(...) Debug(#__VA_ARGS__, __VA_ARGS__); template <typename... Args> void Debug(const char* names, Args&&... args) { std::cerr << names << " = "; ((std::cerr << args << ", "), ...) << "\b\b " << std::endl; } #define ll long long #define ull unsigned long long #define vi vector<int> const ull MOD = 1'000'000'007; ull fastpow(ull x, ull n) { if (n == 0) return 1; if (n & 1 == 1) return x * fastpow(x, n-1) % MOD; ull halfpow = fastpow(x, n/2); return halfpow*halfpow % MOD; } int main() { int n; cin >> n; vector<ull> as(n), bs(n); for (int i = 0; i < n; i++) { cin >> as[i]; cin >> bs[i]; } for (int i = 0; i < n; i++) { cout << fastpow(as[i], bs[i]) << endl; } 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 ... |
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 ... |
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 ... |