cpp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub 9tc/cpp-library

:x: 拡張ユークリッドの互除法
(math/extend-gcd.hpp)

Verified with

Code

template< typename T >
T extendGCD(T a, T b, T &x, T &y){
  T d = a;
  if(b != 0){
    auto t = extendGCD(b, a % b, y, x);
    d = t;
    y -= (a / b) * x;
  }else{
    x = 1;
    y = 0;
  }
  return d;
}
#line 1 "math/extend-gcd.hpp"
template< typename T >
T extendGCD(T a, T b, T &x, T &y){
  T d = a;
  if(b != 0){
    auto t = extendGCD(b, a % b, y, x);
    d = t;
    y -= (a / b) * x;
  }else{
    x = 1;
    y = 0;
  }
  return d;
}
Back to top page