Cod sursa(job #3296508)
| Utilizator | Data | 13 mai 2025 08:01:19 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
const int N=1e5+5;
void euclid(int a , int b ,int & x ,int & y)
{
if(b == 0)
{
x = 1, y = 1;
}
else
{
int x1 , y1;
euclid(b , a % b , x1 , y1);
x = y1;
y = x1 - a / b * y1;
}
}
signed main()
{
ifstream cin("inversmodular.in");ofstream cout("inversmodular.out");
int n,mod;
cin>>n>>mod;
int x=0,y=0;
euclid(n,mod,x,y);
while(x<0) x+=mod;
x%=mod;
cout<<x;
}
