Cod sursa(job #1334250)

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


int pow(int a, int b)
{
    if (b==0) return 1;
    if (b==1) return a%mod;

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

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

}


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

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

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