Task: | Exponentiation |
Sender: | paulschulte |
Submission time: | 2024-11-17 13:44:34 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.11 s | details |
#3 | ACCEPTED | 0.10 s | details |
Code
// ~/.vim/cpp_template.cpp #include <bits/stdc++.h> #include <iostream> #include <vector> #include <algorithm> #include <string> #include <limits> #define REP(i,a,b) for (int i = a; i < b; i++) // Type Aliases for 1D and 2D vectors with initialization #define vi(n, val) vector<int>(n, val) // 1D vector of ints with size n, initialized to val #define vll(n, val) vector<long long>(n, val) // 1D vector of long longs with size n, initialized to val #define ll long long #define vvi(n, m, val) vector<vector<int>>(n, vector<int>(m, val)) // 2D vector of ints (n x m), initialized to val #define vvll(n, m, val) vector<vector<long long>>(n, vector<long long>(m, val)) // 2D vector of long longs (n x m), initialized to val #define LL_INF std::numeric_limits<long long int>::max() #define INF std::numeric_limits<int>::max() using namespace std; template <typename T> void pV(const std::vector<T>& vec, const std::string& label = "Vector") { std::cout << label << ": [ "; for (const auto& elem : vec) { std::cout << elem << " "; } std::cout << "]" << std::endl; } void dfs(int s, vector<bool> *visited, vector<int> (*adj)[]) { if ((*visited)[s]) return; (*visited)[s] = true; // process node s for (auto u: (*adj)[s]) { dfs(u, visited, adj); } } /* // DEPTH-FRIRST-SEARCH vector<int> adj[N]; vector<bool> visited(N, false); int u, v; for(int i = 0; i < M;i++){ cin >> u >> v; u--; v--; adj[u].push_back(v); adj[v].push_back(u); } */ vector<long long> dijkstra(int N, int x, vector<vector<pair<int,int>>> *adj){ vector<bool> processed(N, false); vector<long long> distance(N, LL_INF); priority_queue<pair<long long,int>> q; //for (int i = 1; i <= n; i++) distance[i] = INF; distance[x] = 0; q.push({0,x}); while (!q.empty()) { int a = q.top().second; q.pop(); if (processed[a]) continue; processed[a] = true; for (auto u : (*adj)[a]) { int b = u.first, w = u.second; if (distance[a]+w < distance[b]) { distance[b] = distance[a]+w; q.push({-distance[b],b}); } } } return distance; } /* DIJKSTRA //vector<vector<pair<int,int>>> adj(N, vector<pair<int, int>>(N)); */ const int M = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); // Your code starts here int n; cin >> n; REP(i, 0, n){ long long a, b; cin >> a >> b; if (a == 0 && b == 0){ cout << 1 << "\n"; continue; } long long res = 1; a = a % M; while(b > 0){ if (b % 2 == 1) { res = (res * a) % M; } a = (a * a) % M; b /= 2; } cout << res << "\n"; } cout << 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 ... |