Cod sursa(job #2605798)

Utilizator drknss_Hehe hehe drknss_ Data 25 aprilie 2020 20:18:35
Problema Invers modular Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
# define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 0x3f3f3f3f3f3f3f;
//const ll mod = 1999999973;
const int N = 2e5 + 11;

int a,n;

int poww(int n,int p,int mod){

    int ans = 1;
    while(p){

        if(p%2)ans = (ans * n)%mod;

        n = (n*n)%mod;

        p /= 2;

    }

    return (ans+mod)%mod;
}


int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);

ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");

    cin >> a >> n;

    cout<<poww(a,n-2,n);


return 0;
}