Cod sursa(job #2561999)
| Utilizator | Data | 29 februarie 2020 11:37:08 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
#define rest 1999999973
using namespace std;
unsigned long long n,p,x;
unsigned long long put (unsigned long long a,unsigned long long b)
{
if(b==0)
return 1;
else
if(b==1)
return a%rest;
if(b%2==0)
x=put(a*a%rest,b/2);
else
x=a*put(a*a%rest,(b-1)/2)%rest;
return x;
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
fin>>n>>p;
fout<<put(n,p);
}
