Cod sursa(job #1769797)
Utilizator | Data | 3 octombrie 2016 10:37:12 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n ,p,x;
int m;
int pow( int a,int b)
{
int x;
if(b==0)return 1;
if(b==1)return a;
else if(b%2) return (a%m)*pow(a,b-1);
else
{
x=pow(a,b/2)%m;
return x*x;
}
}
int main()
{
f>>n>>p;
m=1999999997;
g<<pow(n,p)%m<<'\n';
return 0;
}