Cod sursa(job #3203143)

Utilizator suimerchantsui merchant suimerchant Data 13 februarie 2024 10:03:54
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 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=n;
    while(p>1)
    {
        cout<<x<<" "<<p<<"\n";
        if(p%2)
        {
            x=(x*n)%mod;
            p--;
        }
        if(p) x=(x*x)%mod;
        p/=2;
    }
    fout<<x;
    return 0;
}