Cod sursa(job #2330539)
Utilizator | Data | 28 ianuarie 2019 16:12:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <bits/stdc++.h>
#define M 1999999973
#define ll long long
using namespace std;
ifstream f ("lgput.in") ;
ofstream g ("lgput.out") ;
ll N , K ;
ll lgput (ll N , ll K)
{
if (K == 0) return 1 ;
if (K == 1) return N ;
ll a = lgput(N,K/2) ;
if (K % 2 == 0 ) return (a*a)%M ;
if (K % 2 == 1) return ((a*a)%M*N)%M;
}
int main()
{
f >> N >> K;
g << lgput(N,K) << '\n';
return 0;
}