Cod sursa(job #2035114)
Utilizator | Data | 8 octombrie 2017 22:09:07 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 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;
if(b==1)
rez=a;
if(b==0)
rez=1;
while(b>1){
if(b%2==1){
b=b/2;
rez*=rez;
c++;
}
if(b%2==0){
b=b/2;
rez*=rez;
}
}
for(int i=0;i<c;i++)
rez*=a;
g<<rez%1999999973;
}