现在的位置: 首页 > 综合 > 正文

hdu 1019

2013年08月12日 ⁄ 综合 ⁄ 共 324字 ⁄ 字号 评论关闭
//注意用__int64
#include <iostream>
#include <cstdlib>
using namespace std;

__int64 N;
__int64 n;

__int64 gcd(__int64 a,__int64 b)
{
    __int64 s = a*b;
    if(a < b)
    {
         __int64 tmp = a;
         a = b;
         b = tmp;
    }
    __int64 x = a % b;
    while(x != 0)
    {
         a = b;
         b = x;
         x = a % b;
    }
    return s / b;
}

int main()
{
    
    cin>>N;
    __int64 x,y;
    while(N--)
    {
           cin>>n;
           x = y =1;
           for(int i = 0;i < n; i++)
           {
                   cin>>x;
                   y = gcd(x,y);
           }
           cout<<y<<endl;
    }
    return 0;
}

抱歉!评论已关闭.