Cod sursa(job #1170745)
Utilizator | Data | 14 aprilie 2014 14:53:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <cstdio>
#define nr 1999999973
using namespace std;
int main()
{
FILE*f=fopen("lgput.in","r");
FILE*g=fopen("lgput.out","w");
int n,p,mask;
long long prod=1,put;
fscanf(f,"%d%d",&n,&p);
put=n;
for(mask=1;mask<=p;mask<<=1)
{
if(p&mask)
prod=1ll*prod*put%nr;
put=put*put%nr;
}
fprintf(g,"%lld",prod);
return 0;
}