Cod sursa(job #3203151)

Utilizator suimerchantsui merchant suimerchant Data 13 februarie 2024 10:15:22
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;


ifstream fin("lgput.in");
ofstream fout("lgput.out");


long long n,p;


int main()
{
    fin>>n>>p;
    int x=1;
    while(p>1)
    {
        cout<<x<<" "<<p<<"\n";
        if(p%2)
        {
            x=(1ll*x*n)%mod;
            p--;
        }
        x=(1ll*x*x)%mod;
        p/=2;
    }
    fout<<(x*n)%mod;
    return 0;
}