Mai intai trebuie sa te autentifici.
Cod sursa(job #2592740)
Utilizator | Data | 2 aprilie 2020 11:30:22 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.69 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n,p,y;
int main(){
fin >> n >> p;
if(p == 0)
{
fout << 1;
}
else{
y = 1;
while(p > 1)
{
if(p % 2 == 0)
{
n = n * n;
n = n % 1999999973;
p = p / 2;
}
else
{
y = n * y;
n = n * n;
n = n % 1999999973;
y = y % 1999999973;
p = (p - 1) / 2;
}
}
}
fout << n * y % 1999999973;
return 0;
}