Cod sursa(job #2032150)

Utilizator kywyPApescu tiGEriu kywy Data 4 octombrie 2017 17:12:28
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include<cstdio>
#include<algorithm>
using namespace std;
bool cresc;
int main()
{
    FILE* in = fopen("lgput.in", "r"); ///probleme
    FILE* out = fopen("lgput.out", "w");
    int a, b, p = 1;
    fscanf(in, "%d%d", &a, &b);
    while(b > 0)
    {
        if(b % 2 == 1)
        {
            p *= a;
            a = a * a;
            b--;
            b /= 2;
        }
        else
        {
            a = a * a;
            b /= 2;
        }
    }
    int r = p % 1999999973;
    fprintf(out, "%d", r);
}