HDU 1019 Least Common Multiple GCD
2013-08-20 09:22
363 查看
解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数。也就是多次GCD.
View Code
#include<cstdio> #include<iostream> #include<cstring> using namespace std; typedef __int64 INT; INT GCD(INT a,INT b) { return a%b==0? b:GCD(b,a%b); } int main() { int T,n; scanf("%d",&T); while(T--) { scanf("%d",&n); INT c = 1,x; while(n--) { scanf("%I64d",&x); INT tempa = x,tempb = c; if(tempa < tempb) swap(tempa,tempb); c/=GCD(tempa,tempb); c *= x; } printf("%I64d\n",c); } return 0; }
View Code
相关文章推荐
- HDU1019_Least Common Multiple_GCD
- hdu 1019 Least Common Multiple【gcd】
- HDU 1019 Least Common Multiple【GCD】
- HDU-1019-Least Common Multiple( 最大公约数 && 最小公倍数 && GCD )
- HDU 1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- HDU:1019 Least Common Multiple
- HDU1019 Least Common Multiple
- HDU 1019 Least Common Multiple (最小公倍数_水题)
- hdu1019 Least Common Multiple
- hdu1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- HDU 1019 Least Common Multiple 数学题解
- hdu_1019Least Common Multiple(最小公倍数)
- HDU 1019 Least Common Multiple(三个注意的点)
- HDU 1019 - Least Common Multiple
- hdu 1019 Least Common Multiple
- HDU 1019 Least Common Multiple(最小公倍数&最大公约数熟悉)
- HDU1019:Least Common Multiple
- hdu 1019 Least Common Multiple