ëŠ�ë‚€ì � ë°� 설명 ¶
ê³ ë“±í•™êµ�.. 아니 중학êµ�때 부터 ëŠ�꼈지만.. ìœ í�´ë¦¬ë“œ ì•„ì €ì”¨..ì •ë§� 밉다..ã… .ã…œ
최대공약수는 ì €ë²ˆì—� 만들어 놓ì�€ 소스.. 복사~붙여넣기.. ì�´ê±¸ë¡œ í•´ê²°~
그러나 수학ì � ì§€ì‹�ì�˜ 부재로 x,y는 어떻게 구해야 í• ì§€ ëª¨ë¥´ê² ë‹¤ëŠ” íŒ�단하ì—�..
ë‚´ê°€ 수학시간ì—� 주로 ì�¨ë¨¹ì—ˆë�˜.. 대입법! (ì�´ë¦„ë§Œ 거창하지 ì �당히 ì°�어서 넣어본다ë�¼ëŠ” ì�´ì•¼ê¸°..)
ë¬¸ì œì—�서 주어진 규칙ì�„ 만족하는 숫ìž�ê°€ 나오ë�„ë¡� 잔머리 êµ´ë ¤ì„œ 대입시키ë�„ë¡� 해놓았다.^^;
... 대입법ë�„ 훌ë¥í•œ í’€ì�´ë‹¤ ë�...ã… .ã…œ....
최대공약수는 ì €ë²ˆì—� 만들어 놓ì�€ 소스.. 복사~붙여넣기.. ì�´ê±¸ë¡œ í•´ê²°~
그러나 수학ì � ì§€ì‹�ì�˜ 부재로 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;
}










