Cod sursa(job #2348110)
| Utilizator | Data | 19 februarie 2019 13:15:56 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include<cstdio>
long long y=1,x,N=1999999973,p;
int o,l;
char r[100];
long long A()
{
long long s=0;
for(;r[o]<'0'||r[o]>'9';o++);
for(;r[o]>='0'&&r[o]<='9';o++)
s=s*10+r[o]-'0';
return s;
}
void S(long long b)
{
char e[100];
int j;
for(j=0;b;b/=10,j++)
e[j]=b%10+48;
for(j--;j>=0;j--)
r[l++]=e[j];
}
int main()
{
freopen("lgput.in","r",stdin),freopen("lgput.out","w",stdout),fread(r,1,100,stdin),x=A(),p=A();
for(;p;p>>=1,x=(x*x)%N)
if(p&1)
y=(x*y)%N;
S(y),fwrite(r,1,l,stdout);
}
