Task: | Exponentiation |
Sender: | snude |
Submission time: | 2024-11-15 18:56:18 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.17 s | details |
#3 | ACCEPTED | 0.15 s | details |
Code
#include <algorithm> #include <bits/stdc++.h> using namespace std; using ll = long long; // Debug printing #ifdef DEBUG #define deb(fmt, args...) printf("DEBUG: %d: " fmt, __LINE__, ##args) #define debug_print(fmt, args...) printf(fmt, ##args) #else #define deb(fmt, args...) #define debug_print(fmt, args...) #endif void print_array(vector<int> in, const string title = "Vector") { debug_print("DEBUG: %s [\nDEBUG: ", title.c_str()); for (unsigned int i = 0; i < in.size(); i++) { debug_print("%d ", in[i]); } debug_print("\nDEBUG: ] END\n"); } void print_matrix(vector<vector<int>> in, const string title = "Matrix") { debug_print("DEBUG: %s [\nDEBUG: ", title.c_str()); for (unsigned int i = 0; i < in.size(); i++) { for (unsigned int j = 0; j < in[i].size(); j++) { debug_print("%d ", in[i][j]); } debug_print("\nDEBUG: "); } debug_print("DEBUG: ] END\n"); } ll count(int a, int b) { int mod = 1000000007; if (b == 0) return 1; if (b == 1) return a; if (b & 1) { deb("pariton %d\n", b); ll res = (a * count(a, b-1)) % mod; return res; } else { ll res = count(a, b / 2); res = (res * res) % mod; return res; } } int main(int argc, char *argv[]) { ios::sync_with_stdio(0); cin.tie(0); // Read the input parameters int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; cout << count(a, b) << "\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 ... |
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 ... |