38#include "DGtal/arithmetic/IntegerComputer.h"
47void usage(
int,
char** argv )
49 std::cerr <<
"Usage: " << argv[ 0 ] <<
" <a> <b> <c>" << std::endl;
50 std::cerr <<
"\t - solves the diophantine equation ax+by=c by the extended Euclid algorithm." << std::endl;
51 std::cerr <<
"\t - note: c should be a multiple of gcd(a,b)." << std::endl;
57int main(
int argc,
char** argv )
76 if ( ic.isZero( a ) || ic.isZero( b ) )
78 std::cerr <<
"[Error] parameters a and b should be non-null." << std::endl;
81 if ( ic.isNotZero( c % g ) )
83 std::cerr <<
"[Error] parameter c should be a multiple of gcd(a,b)." << std::endl;
89 IC::Vector2I X = ic.extendedEuclid( a, b, c );
90 std::cout <<
"x=" << X[ 0 ] <<
" y=" << X[ 1 ] << std::endl;
91 Integer d = a*X[ 0 ] + b*X[ 1 ];
94 std::cerr <<
"[Internal Error] Output of extended Euclid algorithm is incorrect: " << d <<
" != " << c
95 <<
". This should not happen." << std::endl;
Aim: This class gathers several types and methods to make computation with integers.
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
mpz_class BigInteger
Multi-precision integer with GMP implementation.