Cod sursa(job #2046796)
Utilizator | Data | 24 octombrie 2017 09:42:55 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
#define M = 1999999973
ifstream f("lgput.in");
ofstream g("lgput.out");
int n, p;
int main()
{
f>>n>>p;
long long m=1999999973;
long long x, a=1;
x=n;
while (p>0)
{
if (p%2==1) {
//a=(a*x)%M;
a=(a*x)%m;
}
//x=(x*x)%M;
x=(x*x)%m;
p=p/2;
}
g<<a;
return 0;
}