Cod sursa(job #1987288)
Utilizator | Data | 30 mai 2017 09:48:13 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#define X 1999999973
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int main()
{
long long a, b, rez=1;
in>>a>>b;
while(b!=0)
{
if(b%2==0)
{
a=(a*a)%X;
b=b/2;
}
else
{
rez=(rez*a)%X;
b--;
}
}
out<<rez;
return 0;
}