Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

路过的大牛看看 为啥错了啊 好心人 看一下 为啥老是溢出

Posted by 15038029147 at 2009-12-05 15:02:06 on Problem 3002
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator