| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
路过的大牛看看 为啥错了啊 好心人 看一下 为啥老是溢出#include<stdio.h>
int gcd(int a,int b)
{return b?gcd(b,a%b):a;}
long int lcm(int a,int b)
{return a*b/(gcd(a,b));
}
int main()
{
int mac,wheel;
long int per1,per2;
long int ans;
scanf("%d",&mac);
while(mac--)
{ int flag;
flag=0;
scanf("%d",&wheel);
scanf("%ld",&per1);
if(per1==0)per1=1;
if(wheel==1)ans=per1;
else{wheel-=1;
while(wheel--)
{scanf(" %ld",&per2);
if(per2==0)continue;
else{
ans=lcm(per1,per2);
if(ans>1000000000||ans<0){printf("More than a billion.\n");flag=1;break;}
per1=ans;}
} }
if(flag==0)
printf("%ld\n",ans);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator