Cod sursa(job #1560786)
Utilizator | Data | 3 ianuarie 2016 12:22:46 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
# include <cstdio>
# define MOD 1999999973
using namespace std;
int a,b;
int sol=1;
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d %d\n", &a,&b);
while(b)
{
if(b%2==0) a=(a*a)%MOD,b/=2;
else sol=(sol*a)%MOD,b--;
}
printf("%d\n", sol);
}