Cod sursa(job #3162491)
Utilizator | Data | 29 octombrie 2023 12:40:32 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
const long long MOD = 1999999973;
long long N, P;
long long r = 1;
int main()
{
fin >> N >> P;
while( P != 0 )
{
if( P % 2 == 1 )
{
r = (long long)r * N;
P = P - 1;
}
P = (P / 2);
N = (long long)N * N;
}
fout << r;
return 0;
}