poj--3970 party

http://poj.org/problem?id=3970

题目很水,但是要强调的是:要保证N个数据能够完全输入否则会RE

 1 #include <iostream>
 2 #include<cstdio>
 3 #define ll long long
 4 using namespace std;
 5 ll a,ans,d;
 6 ll gcd(ll a,ll b)
 7 {
 8     if(b==0)
 9     return a;
10     gcd(b,a%b);
11 }
12 int main()
13 {
14     int n,flag;
15     while(~scanf("%d",&n))
16     {
17         if(n==0)
18         break;
19         ans=1;
20         flag=1;
21         for(int i=0;i<n;i++)
22         {
23             scanf("%lld",&a);
24             d=gcd(ans,a);
25             ans=ans/d*a;
26             if(ans>=1000000)
27             {
28                 flag=0;
29                 continue;//注意是continue而不能是break
30             }
31         }
32         if(!flag)
33         printf("Too much money to pay!\n");
34         else
35         printf("The CEO must bring %d pounds.\n",ans);
36     }
37     return 0;
38 }
View Code

 

posted @ 2016-08-03 11:45  Wally的博客  阅读(187)  评论(0编辑  收藏  举报