Cod sursa(job #1761527)
Utilizator | Data | 22 septembrie 2016 14:06:45 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<iostream>
#include<fstream>
using namespace std;
long long int a,b,x=1;
const int val=1999999973;
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>a>>b;
a=a%val;
while(b)
{
if(b%2)
{
x=(x*a)%val;
b--;
}
else
{
a=(a*a)%val;
b/=2;
}
}
g<<x;
return 0;
}