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