Cod sursa(job #3172536)
| Utilizator | Data | 20 noiembrie 2023 20:29:27 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
const long long Mod = 1999999973;
long long putere(int p,long long n){
if(p == 0){
return 1;
}else if(p == 1){
return n%Mod;
}else{
long long x = putere(p/2,n);
if (p%2 == 0){
return x*x%Mod;
}else{
return x*x%Mod*n%Mod;
}
}
}
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
int n,x;
fin>>n>>x;
fout<<putere(x,n);
return 0;
}
