| Task: | Exponentiation |
| Sender: | rikachu |
| Submission time: | 2025-11-17 14:47:03 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.01 s | details |
| #2 | ACCEPTED | 0.12 s | details |
| #3 | ACCEPTED | 0.13 s | details |
Code
#include <bits/stdc++.h>
#include <bitset>
#include <climits>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define IOS ios_base::sync_with_stdio(0), cin.tie(0)
const int INF = 1001001001;
const int MAXN = 100'000;
const char br = '\n';
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
int nxt() {
int x;
cin >> x;
return x;
}
unsigned exp_by_squaring(size_t a, size_t b) {
bitset<INT_WIDTH> e(b);
size_t msb = 0;
for (size_t i = 0; i <= e.size(); i++) {
if (e[i]) {
msb = i;
}
}
constexpr size_t mod = 1E9 + 7;
auto res = a;
for (int i = msb - 1; i >= 0; i--) {
res = res * res % mod;
if (e[i])
res = res * a % mod;
}
return res;
}
int main() {
IOS;
int n = nxt();
for (int i = 0; i < n; i++) {
size_t a, b;
cin >> a >> b;
cout << exp_by_squaring(a, b) << br;
}
return 0;
}
Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 10201 0 0 0 1 0 2 0 3 ... |
| correct output |
|---|
| 1 0 0 0 0 ... |
| user output |
|---|
| 0 0 0 0 0 ... Truncated |
Feedback: Incorrect character on line 1 col 1: expected "1", got "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 ... 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 |
