Cod sursa(job #1646070)

Utilizator theodor1289Theodor Amariucai theodor1289 Data 10 martie 2016 14:56:15
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, k, a, b;

int main()
{
    fin>>n>>k;
    a=b=n;

    while(k>1)
    {
        if(k%2==0)
        {
            a*=a%MOD;
            k/=2;
        }
        else
        {
            b*=n%MOD;
            k--;
        }
    }

    fout<<a*(b/n)%MOD;
    return 0;
}