Cod sursa(job #903622)
Utilizator | Gabriel-Robert Inelus gabrielinelus | Data | 1 martie 2013 23:40:58 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
#include <iostream>
#define mod 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long putere(long long a,long long b)
{
long long x=a;
if(b==0)return 1;
while(b!=1&&b!=0)
if(b%2==0)
{a*=a;b/=2;a%=mod;}
else
{a*=x;b--;a%=mod;}
return a;
}
int main()
{
long long a,b;
fin>>a>>b;
fout<<putere(a,b);
return 0;
}