Cod sursa(job #1041218)

Utilizator 0051David Sera 0051 Data 25 noiembrie 2013 17:22:34
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <iostream>
#include <fstream>

using namespace std;

#define c 1999999973

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

int main()
{
    long long int a,b;
    fin>>a>>b;
    long long int p;
    p=1;
    while(b)
        {if(b%2==1)
            {p=(p*a)%c;
            b--;
            }
        a=(a*a)%c;
        b=b/2;
        }
    fout<<p<<endl;
    fin.close();
    fout.close();
    return 0;
}