数论——gcd,lcd

离散数学中数论公式:

整数a,b的最大公约数gcd(a,b)=gcd(b,a%b) ————(1)

同时我们知道gcd(x,0)=x   ————(2)

通过(1)式的不断循环迭代,可以得(2)式子

那么可以可以写代码了

#include<stdio.h>
int main(){
    int a,b,c;

    a=10,b=15;

    while(b!=0){     //gcd(a,b)=gcd(b,a%b)
        c=b;
        b=a%b;
        a=c;
    }
    printf("%d",a);
}

  

原文地址:https://www.cnblogs.com/z-bear/p/7701894.html