最小公倍数=a1.b1.c1.d =a1.d.b1.d.c1.d/d²=abc/d²求两个数的最大公因数,可以用辗转相除法:int gys(int a,int b){if(!(a〉0)&&(b〉0)) return (-1);//错 else if(a〈b) return (gys(b,a));else if(!(a%b)) return (b);else return(gys(b,a...
三个数的最大公约数,就是其中任意2个数的最大公约数与第三个数的最大公约数。include <stdio.h>void main(){int a,b,c,d;printf("input three number:");scanf("%d %d %d",&a,&b,&d);c = a%b;while( c > 0 ){a = b;b = c;c = a%b;}a = d;c = a%b;while( ...
int(*get_factors(int num)); int min(int, int); int a, b; while(scanf("%d,%d", &a, &b) != EOF) { int (* as)[a], (*bs)[b]; int i, j; float k; j = 1; as = get_factors(a); bs = get_factors(b); //倒着遍历匹配相同因数即为最大 for (i = min(a,b); i ...
先求三个数的最小值,min 再取i从1开始到min判断是否是3个数的因数,跳出的i减一为结果
include <iostream> using namespace std; int main() { int a, b, c; cin>>a>>b>>c; int min = a; if(min > b) min = b; if(min > c) min = c; int i = min; int gcd = 1; while(i) { if(a%i==0 && b%i==0 && c%i==0) { gcd = i; break; } i--;...