Cod sursa(job #1526027)

Utilizator kassay_akosKassay Akos kassay_akos Data 15 noiembrie 2015 20:29:21
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>
using namespace std;

const int oo = 1999999973 ;


int main()
{
    freopen("lgput.in","r",stdin);
	freopen("lgput.out","w",stdout);
	int n,m ;

	scanf("%d %d",&n ,&m);
	unsigned long long x = n ,y = 1;

	if (n == 0) printf("1");
	while (m > 1) {
        if (m %2 == 0) {
            x = (x*x) % oo ;
            m = m / 2;
        }
        else {
            y = (y*x)%oo;
            x = (x*x)%oo;
            n = (n-1)/2;
        }
	}
    int result = (x*y) % oo ;
    printf("%d" , result);
	fclose(stdin);
	fclose(stdout);
    return 0;
}