程そ计
ㄢ俱计 A 籔 B ぇ程そ计计厩﹚竡
璝Τ计 p 俱埃 A 籔 B玥 p 嘿 A 籔 B そ计
礛τ渤そ计い程嘿 A B ㄢ计程そ计
劣锣埃猭(稼碭ń眔衡玥Euclidean algorithm)璶瞶阶
璝 r  A 埃 B 緇计玥 A 籔 B そ计ゲ籔 B 籔 r そ计

ㄒ
A=60B=36
玥 r = 24
A 籔 B そ计 2, 3, 4, 6, 12
B 籔 r そ计 2, 3, 4, 6, 12
ㄢЧ (ǎ劣锣埃猭闽靡)
琂礛 A 籔 B そ计穦籔 B 籔 緇计 r そ计玥ノ瞶盢 B 籔 r 蠢传Θ穝 A 籔 B玻ネ穝 rㄌ摸崩 r 箂琌碞琌程そ计?
ㄒ簍絤
A=60B=36 眔 r = 24
A=36B=24 眔 r = 12
A=24B=12 眔 r = 0
眔程そ计 12
A 璝 B 猭ョ
A=36B=60 眔 r=36
A=60B=36 眔 r=24 ()

パ璝ㄧ计 gcd(a,b) 琌― a 籔 b 程そ计玥 gcd(a,b) = gcd(b,r)讽 r = 0  b   A 籔 B 程そ计
患癹ㄢ璶
    A.gcd (a , b) 籔 gcd(b , r) 闽玒 gcd(a , b) = gcd(b,a%b)
    B.sum(b , 0) = b

癹伴
患癹
#include <stdio.h>
#include <stdlib.h>

int main(){
int i, a, b, r;
scanf("%d %d",&a,&b);
printf("gcd(%d,%d) =",a,b);
r=a%b;
while(r!=0){
    a=b;
    b=r;
    r=a%b;
}
printf("%d\n",b);
return(0);
}
#include <stdio.h>
#include <stdlib.h>

int gcd(int a , int b){
if(b==0)
    return(a);
else
    return(gcd(b , a%b));
}

int main(){
int a, b, k;
scanf("%d %d",&a, &b);
k=gcd(a, b);
printf("gcd(%d,%d) = %d\n",a,b,k);
return(0);
}