zoukankan      html  css  js  c++  java
  • uva11827gcd

    gcd裸题,不过输入要注意gets会tle,要用快速读入

    #include<map>
    #include<set>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstdio>
    #include<cassert>
    #include<iomanip>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define pi acos(-1.0)
    #define ll long long
    #define mod 1000000007
    #define ls l,m,rt<<1
    #define rs m+1,r,rt<<1|1
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    
    using namespace std;
    
    const double g=10.0,eps=1e-7;
    const int N=100000+10,maxn=500+100,inf=0x3f3f3f;
    
    ll a[N];
    ll gcd(ll a,ll b)
    {
        if(a<b)swap(a,b);
        return b?gcd(b,a%b):a;
    }
    int main()
    {
      /*  ios::sync_with_stdio(false);
        cin.tie(0);*/
        ll n,ans=0;
        scanf("%d",&n);
        while (getchar() != '\n');
        while (n --) {
            char buf;
            int cnt = 0;
            while ((buf = getchar()) != '\n')
            if (buf >= '0' && buf <= '9') {
            ungetc(buf,stdin);
            scanf("%d",&a[cnt++]);
            }
            ll ans=0;
            for(int i=0;i<cnt;i++)
                for(int j=i+1;j<cnt;j++)
                    ans=max(ans,gcd(a[i],a[j]));
            printf("%lld\n",ans);
        }
        return 0;
    }
    /*********************
    3
    10 20 30 40
    7 5 12
    125 15 25
    *********************/
    View Code
  • 相关阅读:
    数组的操作方法
    数组遍历的方法以及区别
    组件内的守卫
    路由守卫
    软件工程
    java web (j2ee)学习路线 —— 将青春交给命运
    团队作业(一)- 第五组
    软件工程
    软件工程-第二次作业
    java局部/成员/静态/实例变量
  • 原文地址:https://www.cnblogs.com/acjiumeng/p/7212101.html
Copyright © 2011-2022 走看看