Cod sursa(job #1794037)

Utilizator Coroian_DavidCoroian David Coroian_David Data 31 octombrie 2016 20:25:24
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>

#include <cstdio>

using namespace std;

FILE *f, *g;

long long a, b;

long long putere(long long a, long long b)
{
    long long p = 1, i, c = a;

    for(i = 0; (1 << i) <= b; i ++)
    {

        if(((1 << i) & b) > 0)
        {
            p = (p * c) % 1999999973;
        }

        c *= c;

        c %= 1999999973;
    }

    return p;
}

void readFile()
{
    f = fopen("lgput.in", "r");

    fscanf(f, "%lld%lld", &a, &b);

    fclose(f);
}

void solveAndPrint()
{
    g = fopen("lgput.out", "w");

    fprintf(g, "%lld\n", putere(a, b));

    fclose(g);
}

int main()
{
    readFile();

    solveAndPrint();

    return 0;
}