Cod sursa(job #2048248)
Utilizator | Marvelous marvelous | Data | 25 octombrie 2017 21:03:38 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
ifstream F("lgput.in");
ofstream G("lgput.out");
int p;
long long ans = 1, n;
const int MOD = 1999999973;
int main()
{
F >> n >> p;
for( int i = 0; ( 1 << i ) <= p; ++ i )
{
if( ( ( 1 << i ) & p ) ) ans = 1LL * (n % MOD) * (ans % MOD);
ans %= MOD;
n = 1LL * (n % MOD) * (n % MOD);
}
G << ans;
return 0;
}