Cod sursa(job #2760006)
| Utilizator | Data | 22 iunie 2021 13:27:37 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("algebra2.in");
ofstream fout("algebra2.out");
const ll MOD = 1000000009;
ll n;
ll lgput(ll n,ll p){
ll rasp=1;
while(p!=0){
if(p%2==1){
rasp=(1LL*rasp*n)%MOD;
p--;
}
n=(1LL*n*n)%MOD;
p/=2;
}
return rasp;
}
int main()
{
fin >> n;
if(n%2==1) fout << lgput(lgput(n,n),(n+1)/2);
else fout << lgput(lgput(n,n+1),n/2);
return 0;
}
