Cod sursa(job #680764)

Utilizator repp4raduRadu-Andrei Szasz repp4radu Data 15 februarie 2012 21:48:05
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <cstdio>

#define rest 1999999973

using namespace std;

long long a, b, x;

void citire()
{
    freopen("lgput.in", "r", stdin);
    scanf("%d %d", &a, &b);
    fclose(stdin);
}

void solve()
{
    x = 1;
    while(b > 0)
    {
        if(b % 2)
        {
            x *= a;
            x %= rest;
            b--;
        }
        else
        {
            a *= a;
            a %= rest;
            b /= 2;
        }
    }
}

void afisare()
{
    freopen("lgput.out", "w", stdout);
    printf("%d", x % rest);
    fclose(stdout);
}

int main()
{
    citire();
    solve();
    afisare();
    return 0;
}