Cod sursa(job #1135873)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 8 martie 2014 15:08:56
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <cstdio>

#define MOD 1999999973

using namespace std;

long long lg_put(long long a,long long b)
{
    long long x1 = a,x2 = 1;
    if( b == 0 )return 1;
    if( b == 1 )return a;
    while(b > 1)
    {
        if(b & 1)
        {
            x2 = (x1 * x2) % MOD;
            b^=1;
        }
        else
        {
            x1 = (x1 * x1) % MOD;
            b>>=1;
        }
    }
    return (x1 * x2) % MOD;
}

int main()
{
    freopen("lgput.in","r",stdin);
    freopen("lgput.out","w",stdout);
    long long a,b;
    scanf("%lld %lld",&a,&b);
    printf("%lld\n",lg_put(a,b));
    return 0;
}