#include <stdio.h>
#include <stdlib.h>
struct Triple
{
int gcd;
int coef1;
int coef2;
};
struct abc{};
struct Triple *chineseRemainderTheorem(int a, int b)
{
struct Triple *triple;
if(b == 0){
struct Triple *triple = (struct Triple*)malloc(sizeof(struct Triple));
triple->gcd = a;
triple->coef1 = 1;
triple->coef2 = 0;
return triple;
}
triple = chineseRemainderTheorem(b, a%b);
int tmp = triple->coef1;
triple->coef1 = triple->coef2;
triple->coef2 = tmp - (a/b)*(triple->coef2);
return triple;
}
int main()
{
struct Triple *triple;
triple = chineseRemainderTheorem(80, 68); // ntu csie 96
printf("(%d, %d, %d)\n", triple->gcd, triple->coef1, triple->coef2);
return 0;
}
留言列表