Cod sursa(job #2049187)
Utilizator | Data | 26 octombrie 2017 22:14:39 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
#define mod 1999999973
using namespace std;
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n, p, s = 1, a = 1;
f>>n>>p;
while(p!=0){
if(p%2==1){
s =s*n%mod;
--p;
}
if(p>0){
p/=2;
n =n*n%mod;
}
}
g<<s%mod;
}