Cod sursa(job #1917383)
Utilizator | Data | 9 martie 2017 12:07:51 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
#define cheie 1999999973
int n, p;
void Citire()
{
fin >> n >> p;
fin.close();
}
int putere(int n, int p)
{
int x = 1;
while(p)
{
if (p % 2 == 1)
x = (x * n)%cheie;
n = (n * n) % cheie;
p/=2;
}
return x;
}
int main()
{
Citire();
fout << putere(n, p) % cheie << "\n";
return 0;
}