标签:style io for sp amp on size c as
题解:求n个数的最小公倍数,一个一个算就可以了,需要注意的是LCM先除GCD再乘,因为先乘有可能会超范围,1WA的代价。
#include <cstdio> int T,n,a,b; int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);} int main(){ scanf("%d",&T); while(T--){ scanf("%d",&n);a=1; for(int i=0;i<n;i++){ scanf("%d",&b); a=a/gcd(a,b)*b; }printf("%d\n",a); }return 0; }
HDU 1019 Least Common Multiple
标签:style io for sp amp on size c as
原文地址:http://www.cnblogs.com/forever97/p/3946028.html