Cod sursa(job #2386631)

Utilizator Ilie_MityIlie Dumitru Ilie_Mity Data 23 martie 2019 12:19:54
Problema Invers modular Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <cstdio> //Ilie Dumitru

using namespace std;

int main ()
{
    FILE *f,*g;
    long long int y,N,A,sol;
    f=fopen("inversmodular.in", "r");
    fscanf(f, "%lli", &A);
    fscanf(f, "%lli", &N);
    fclose(f);
    switch(A)
    {
    case(1):
        sol=N-1;
        break;
    case(2):
        sol=N/2+1;
        break;
    default:
        {
            bool ok=true;
            for(y=1;ok;y++)
            {
                int aux=N*y+1;
                if(aux%A==0)
                {
                    sol=aux/A;
                    ok=false;
                }
            }
        }
    }
    g=fopen("inversmodular.out", "w");
    fprintf(g, "%lli\n", sol);
    fclose(g);
    return 0;
}