Cod sursa(job #2384835)
Utilizator | Data | 21 martie 2019 11:08:24 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
#define Mod 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long N,M,a,b;
int cnt;
bool V[350];
int main()
{
f>>N>>M;
a=M;
b=N;
while(a)
{
if(a%2) V[++cnt]=1;
else V[++cnt]=0;
a/=2;
}
for(int i=cnt-1;i>=1;i--)
{
if(V[i]==0) N=(N*N)%Mod;
else N=(N*N*b)%Mod;
}
g<<N;
return 0;
}