Cod sursa(job #1380683)
Utilizator | Data | 8 martie 2015 10:34:51 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int put(int n, int p)
{
int rez=1;
while(p>0)
{
if(p & 1)
rez=(long long)rez*n%MOD;
n=(long long)n*n%MOD;
p = (p >> 1);
}
return rez;
}
int main()
{
int n,p;
fin>>n>>p;
fout<<put(n,p);
return 0;
}