Cod sursa(job #2461622)
Utilizator | Bocan Sabin Andrei sabinandrei | Data | 25 septembrie 2019 21:41:59 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.57 kb |
//
// main.cpp
// exp
//
// Created by Sabin Andrei on 9/25/19.
// Copyright © 2019 Sabin Andrei. All rights reserved.
//
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
#define N 1999999973
long int expp(long int baza,long int exp)
{
if (exp==0)
return 1;
if (exp==1)
return baza%N;
long int t=expp(baza,exp/2);
t=(t*t)%N;
if (exp%2==0)
return t;
else
return ((baza%N)*t)%N;
}
int main()
{
long int n,p;
in>>n>>p;
out<<expp(n,p);
}