Cod sursa(job #3135316)
| Utilizator | Data | 2 iunie 2023 17:34:56 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <iostream>
#include <math.h>
#include <fstream>
#define MAX 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long int power(long long n, long long p)
{
long long int finale;
if(p==0)
{
return 1;
}
if(p%2==1)
{
return (n*power(n,p-1))%MAX;
}
else
finale= power(n,p/2)%MAX;
return (finale *finale)*MAX;
}
int main()
{
long long int n,p,finale;
fin>>n>>p;
finale=power(n,p);
fout << finale;
return 0;
}
