Mai intai trebuie sa te autentifici.
Cod sursa(job #2027927)
| Utilizator | Data | 26 septembrie 2017 21:23:57 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
//i'm never leaving this project
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const int mod=1999999973;
long long base;
long long p;
long long logpow(long long base, long long p)
{
int b=32;
long long A=1;
while(b>=0)
{
if(p&1LL<<b)
{
A=(A*A)%mod;
A=(A*base)%mod;
}
else
{
A=(A*A)%mod;
}
b--;
}
return A;
}
int main()
{
f>>base>>p;
g<<logpow(base,p)<<'\n';
return 0;
}
