| Task: | Exponentiation |
| Sender: | Isak |
| Submission time: | 2025-11-17 15:38:09 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | details |
| #2 | ACCEPTED | 0.16 s | details |
| #3 | ACCEPTED | 0.15 s | details |
Code
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define LOOP(i,s,e) for (uint64_t i = (s); i < (e); i++)
#define SCAN(...) if (scanf(__VA_ARGS__) == 0) return EXIT_FAILURE
#define MOD 1000000007
uint64_t exp(uint64_t x, uint64_t n){
if (n == 0)
return 1;
if (n % 2 == 0) // even
return (exp(x, n/2) * exp(x, n/2)) % MOD;
// odd
return (exp(x, n-1) * x) % MOD;
}
int main() {
uint64_t n = 0;
SCAN("%ld", &n);
// main algo
uint64_t a, b;
LOOP(i, 0, n){
SCAN("%ld %ld", &a, &b);
printf("%ld\n", exp(a, b));
}
return EXIT_SUCCESS;
}
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 |
