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 |
SOS!!!!高手 为什么会WA ?#include<iostream.h> int Max=1000000000; int bei(long int m,long int n) {int a,b,r,t; long int sum=0,t; if(m>n){a=m;b=n;} else{a=n;b=m;} r=b; while(r!=0) {r=a%b; a=b; b=r; } t=m/a; for(int i=1;i<=n;i++) {sum+=t; if(sum>Max)return 0; } return sum; } void main() {int n,w; long int p[1005],t; cin>>n; for(int i=1;i<=n;i++) {cin>>w; if(w==0){cout<<"0"<<endl;continue;} for(int j=1;j<=w;j++) cin>>p[j]; if(w==1){cout<<p[1]<<endl;continue;} for(j=2,t=bei(p[1],p[2]);j<=w;j++) {if(!t){cout<<"More than a billion."<<endl;break;} else t=bei(t,p[j]); } if(t)cout<<t<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator