Cod sursa(job #2365888)
Utilizator | Data | 4 martie 2019 17:11:17 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <iostream>
#include <fstream>
#define ll long long
using namespace std;
ifstream x("inversmodular.in");
ofstream y("inversmodular.out");
ll a,n;
int inv(int a, int n)
{
int p=n-2,r=1;
while(p)
{
if(p%2)
{
r=(1LL*r*a)%n;
}
a=(1LL*a*a)%n;
p/=2;
}
return r;
}
int main()
{
x>>a>>n;
y<<inv(a,n);
x.close();
y.close();
return 0;
}