Cod sursa(job #2545290)
Utilizator | Data | 12 februarie 2020 23:02:20 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
#define CAT 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long putere(int n, int p)
{
long long sol = 1;
while(p)
{
if(p % 2 == 1)
sol = (sol * (n %CAT)) % CAT;
n = (n%CAT * n%CAT) % CAT;
p /= 2;
}
return sol;
}
int main()
{
int n,p; f>>n>>p;
g<<putere(n,p);
}