标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33105 Accepted Submission(s): 12478
#include "stdio.h" int leastCommon(int a,int b) { if(b==0) return a; return leastCommon(b,a%b); } int main() { int n,m,t1,t2; while(scanf("%d",&n)!=-1) { while(n--) { scanf("%d",&m); scanf("%d",&t1); m--; while(m--) { scanf("%d",&t2); t1=t1/leastCommon(t1,t2)*t2; } printf("%d\n", t1); } } }
这个需要注意:
t1=t1/leastCommon(t1,t2)*t2;
如果写成
t1=t1*t2/leastCommon(t1,t2);
就会越界!
标签:
原文地址:http://www.cnblogs.com/tianyong/p/4176813.html