Cod sursa(job #1343591)
Utilizator | Data | 15 februarie 2015 17:20:39 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long rez=1,a,n;
void citire()
{
fin>>a>>n;
}
void putere(long long x,long long n,long long &rez)
{
while(n>0)
{
if(n%2==0)
{x=x*x;
n=n/2;
}
else
{
rez=rez*x;
x=x*x;
n=n/2;
}
}
}
int main()
{
citire();
putere(a,n-2,rez);
fout<<rez;
return 0;
}