Cod sursa(job #3231973)
Utilizator | Data | 28 mai 2024 13:19:48 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
typedef long long int lint;
lint A, N;
int main(){
fin >> A >> N;
// calculam A la puterea N-2
lint y = N-2, rez = 1;
while(y > 0){
if(y%2 != 0){
rez = rez * A % N;
y--;
}
else{
A = A * A % N;
y /= 2;
}
}
fout << rez;
fin.close();
fout.close();
return 0;
}