Cod sursa(job #1895828)

Utilizator SkiryFarauanu Ionut Skiry Data 28 februarie 2017 11:16:44
Problema Invers modular Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>
#include <math.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
unsigned long long a,b,nr=1,copie;
int main()
{
    f>>a>>b;
    int ok=1;
    copie=b;
    for(int k=2;k<=sqrt(b)&&ok;k++)
        if(b%k==0) ok=0;
    b--;
    if(ok) b--;
    while(b)
    {
        if(b&1)
        {
            nr*=a;
            b--;
        }
        a*=a;
        b>>=1;
    }
    g<<nr%copie;
    return 0;
}