Cod sursa(job #2943708)
Utilizator | Data | 21 noiembrie 2022 15:46:36 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int M=1999999973;
int putere(int a, int n)
{
int p=1;
while(n!=0)
{
int cifb=n%2;
if(cifb!=0)
{
p=(long long)p*a%M;
}
a=(long long)a*a%M;
n/=2;
}
return p;
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int N, P;
fin>>N>>P;
int A=putere(N, P);
fout<<A%M;
}