Cod sursa(job #423388)

Utilizator alexandru92alexandru alexandru92 Data 23 martie 2010 20:26:59
Problema Invers modular Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
/* 
 * File:   main.cpp
 * Author: virtualdemon
 *
 * Created on March 23, 2010, 4:30 PM
 */
#include <cstdio>
#include <cstdlib>


/*
 *
 */
using namespace std;
inline void gcd( int a, int b, int& x, int& y )
{
    if( !b )
    {
        x=1;
        y=0;
        return;
    }
    int x0, y0;
    gcd( b, a%b, x0, y0 );
    x=y0;
    y=x0-a/b*y0;
}
int main( void )
{
    int A, N, inv, y;
    fscanf( fopen( "inversmodular.in", "rt" ), "%d%d", &A, &N );
    gcd( A, N, inv, y );
    if( inv <= 0 )
        inv=N+inv%N;
    fprintf( fopen( "inversmodular.out", "wt" ), "%d", inv );
    return EXIT_SUCCESS;
}