Cod sursa(job #2666479)

Utilizator ttttDumitru Andrei Denis tttt Data 1 noiembrie 2020 23:04:15
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
#define mod 1999999973

using namespace std;
typedef long long ll;
typedef pair<ll,ll>pii;
typedef pair<ll,pii>muchie;

const ll NMAX = 100001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 101;

using ll=long long;

int main()
{
    ifstream cin("lgput.in");
    ofstream cout("lgput.out");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,p;
    cin >> n >> p;
    ll power = n;
    ll ans = 1;
    ll exp = 1;
    while(exp <= p){
        if(exp & p){
            ans *= power;
            ans %= mod;
        }
        power = (power % mod * power % mod) % mod;
        power %= mod;
        exp *= 2;
    }
    cout << ans << "\n";
    cin.close();
    cout.close();
    return 0;
}