Cod sursa(job #2708115)
| Utilizator | Data | 18 februarie 2021 12:38:11 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include<iostream>
#include<fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int putere(int n, int p)
{
int r = 1;
while(p)
{
if(p % 2 == 1)
r = (r * n) % MOD, p--;
else
n = (n * n) % MOD, p/=2;
}
return r;
}
void citire()
{
int n, p;
fin >> n >> p;
fout << putere(n, p);
}
int main()
{
citire();
return 0;
}
