fzu Problem 1396 Large Caclulating Work

题目:1396 Large Caclulating Work 

思路:题目意思很绕,但是化简之后发现其实就是求n个数的最大公约数

 

复制代码
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
long long gcd(long long a,long long b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main()
{
    int t;
    int cas=0;
    while(scanf("%d",&t),t)
    {
        int n,ans;
        scanf("%d",&n);
        ans=n;
        for(int i=2;i<=t;i++)
        {
            scanf("%d",&n);
            ans=gcd(ans,n);
        }
        printf("Test Data %d:\n",++cas);
        printf("%d\n",ans);
    }
    return 0;
}
View Code
复制代码

 

posted @   over_flow  阅读(167)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示