Cod sursa(job #1334270)

Utilizator Vele_GeorgeVele George Vele_George Data 4 februarie 2015 09:55:12
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <iostream>
#include <fstream>
#define mod 1999999973
#define int64 long long
using namespace std;


int64 pow(int64 a, int64 b)
{
    if (b==0) return 1;
    if (b==1) return a;

    int64 h=pow(a,b/2)%mod;
          h=(h*h)%mod;

    if (b%2==0) return h%mod;
                return (a*h)%mod;

}


int main()
{
    int64 n,m;
    ifstream f("lgput.in");
    ofstream g("lgput.out");

    f >> n >> m;
    g << pow(n,m);

    f.close();
    g.close();
    return 0;
}