Cod sursa(job #2042680)
Utilizator | Data | 18 octombrie 2017 22:02:28 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
int a,b,t;
unsigned long long int rez, mod=1999999973;
f>>a>>b;
t=1;
if(b==0)
rez = 1;
if(b==1)
rez = a;
while(b>1){
if(b%2==0){
a=(a*a)%mod;
b=b/2;
}
else{
t=a;
a=(a*a)%mod;
b=b/2;
}
}
rez=(a*t)%mod;
g<<rez;
}