U E D R , A S I H C RSS

Euclid Problem/조현태

.. .. .. ..ㅠ.ㅜ
.. ~.. ~
x,y ..
.. ! ( ..)
.^^;
... ...ㅠ.ㅜ....

~cpp 
#include <stdio.h>

int Get_GCM(int , int );
void Get_x_y(int, int, int*, int*, int );

void main()
{
	int input_a, input_b;
	while (1)
	{
		int x=0, y=0, gcm=0;
		printf ("  .(0,0) \n>>");
		scanf ("%d%d",&input_a,&input_b);
		if (0==input_a && 0==input_b)
			break;
		gcm=Get_GCM(input_a, input_b);
		Get_x_y(input_a, input_b, &x, &y, gcm);
		printf (" : x=%d\ty=%d\tGCM=%d\n",x,y,gcm);
	}
}

void Get_x_y(int number_a, int number_b, int* x, int* y, int gcm)
{
	int *temp_large, *temp_small, temp_plus=1;
	if (number_a>number_b)
	{
		temp_large=x;
		temp_small=y;
	}
	else
	{
		temp_large=y;
		temp_small=x;
	}
	while(number_a*(*x)+number_b*(*y)!=gcm)
	{
		if (temp_plus>0 && number_a*(*x)+number_b*(*y)>gcm)
		{
			*temp_large=0;
			temp_plus=-1;
		}
		else if (temp_plus<0 && number_a*(*x)+number_b*(*y)<gcm)
		{
			*temp_large=0;
			temp_plus=1;
			if (*temp_small>0)
				*temp_small*=-1;
			else
				*temp_small=*temp_small*(-1)+1;
		}
		else
			*temp_large+=temp_plus;
	}
}

int Get_GCM(int number_a, int number_b)
{
	int temp;
	while (temp=number_a%number_b)
	{
		number_a=number_b;
		number_b=temp;
	}
	return number_b;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:14
Processing time 0.0282 sec