확장 GCD 알고리즘에 대한 다음과 같은 알고리즘을 작성했습니다. 어떻게 트리플을 반환 할 수 있는지 아무도 알 수 없습니까?확장 된 GCD 알고리즘
#include<iostream>
#include<math.h>
using namespace std;
int gcd(int a,int b) { return (b==0 ?a:gcd(b,a%b));}
long long gcd(long a,long b) { return (b==0 ?a:gcd(b,a%b));}
template<class Int> Int gcd(Int a,Int b) { return (b==0 ?a:gcd(b,a%b));}
template<class Int>
struct Triple
{
Int d,x,y;
Triple(Int q,Int w,Int e) :d(q),x(w),y(e)) {}
};
//extended GCD
/* computes d=gcd(a,b)
also x and y such that d=a*x+y*b and return tripls (d,x,y)
*/
template<class Int>
Triple <Int> egcd(Int a,Int b) {
if(!b) return Triple<Int>(a,Int(1),Int(0));
Triple<int>q=egcd(b,a%b);
return Triple<Int>(q.d,q.y,q.x-a/b*q.y);
}
int main(){
int a=35;
int b=13;
return 0;
}
내 트리플 구조체 생성자를 사용하여 마무리하는 방법 나에게
'C++ 11'에서'std :: tuple'을 살펴볼 수 있습니다. –