Cod sursa(job #1799598)
Utilizator | Data | 6 noiembrie 2016 15:48:47 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{long long x,n,y=1;
f>>x>>n;
if(n<0) x=1/x,n=-n;
if(n==0) x=1;
while(n>1) if(n%2==0) x*=x,x%=1999999973,n=n/2;
else y*=x,y%=1999999973,x*=x,x%=1999999973,n=(n-1)/2;
g<<x*y%1999999973;
}