Cod sursa(job #2391283)
| Utilizator | Data | 28 martie 2019 18:59:54 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int v = 1999999973;
long calc_putere(int n, int p)
{
long r =1 ;
while(p)
{
if(p%2 == 1 ) r = (1LL * r * n)% v;
n=(1LL *n *n)%v;
p= p/2;
}
return r;
}
void citire(int &n, int & p)
{
ifstream in("lgput.in");
in>>n>>p;
in.close();
}
int main()
{
int n, p;
citire(n,p);
ofstream out("lgput.out");
out<<calc_putere(n,p) ;
return 0;
}
