Cod sursa(job #3257200)
Utilizator | Data | 16 noiembrie 2024 21:22:27 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
int n, p;
unsigned long long sol = 1, exp;
f >> n >> p;
exp = n;
while ( p != 0 )
{
if ( p % 2 == 1 )
sol = ( sol * exp ) % MOD;
exp = ( exp * exp ) % MOD;
p /= 2;
}
g << sol;
return 0;
}