Cod sursa(job #3227988)
| Utilizator | Data | 4 mai 2024 17:16:27 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int M = 1999999973;
long int power(long int n, long int p) //computes n ^ p modulo M
{
if(p == 0)
return 1;
if(p % 2)
return (n * power(n * n, p / 2)) % M;
return power(n * n, p / 2) % M;
}
int main(void)
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long int n, p;
fin >> n >> p;
fout << power(n, p) << "\n";
fin.close();
fout.close();
return 0;
}