• 密码


    https://www.luogu.org/problem/show?pid=3518

    问题描述:

      

    输入格式:n,k

         k个非负整数

    输出格式:一个数

    样例:入 42 5

          28 31 10 38 24

       出 14

    k<=250 000 ,k<=n<=10^14;

    分析;当x为密码时,x 的因数和倍数都是密码。

         所以只需找到最小的x,即可。

    代码目标:找出的gcd(a[k],n)所有因子记在q数组中。

         从中删去gcd(a[k],a[1~k-1])的因子。

         q中剩下的最小因子,即为所求x。

         输出n/x 就OK了

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<climits>
    #include<string>
    #include<cstdlib>
    //#include<ctime>
    using namespace std;
    #define LL long long
    LL n,k,i,j;
    LL a[1000000],q[5000000],cnt=0,ans;
    bool f[1300000];
    LL gcd(LL a,LL b)
    {
        LL t;
        while(b)
        {
            t=a;
            a=b;b=t%b;
        }
        return a;
    } 
    int main()
    {
        scanf("%lld%lld",&n,&k);
        for(i=1;i<=k;i++)
            scanf("%lld",&a[i]);
        a[k]=gcd(a[k],n);
        for(LL i=1;i<k;i++)
            a[i]=gcd(a[i],a[k]);
        for(i=1;i*i<=a[k];i++)
        if(a[k]%i==0)    
        {
            q[++cnt]=i;
            if(i*i!=a[k])
                q[++cnt]=a[k]/i;
        }
        sort(q+1,q+cnt+1);
        for(LL i=1;i<k;i++)
        f[lower_bound(q+1,q+cnt+1,a[i])-q]=1;//莫意思
        for(i=1;i<=cnt;i++)
        if(f[i])
            for( j=1;j<i;j++)
            if(q[i]%q[j]==0) 
                f[j]=1;
        
        for(ans=1;f[ans];ans++);
         printf("%lld",n/q[ans]);
        return 0; 
    }
  • 相关阅读:
    spring filter and interceptor
    spring 与 swagger 2 的整合
    spring 异步操作
    图片延迟加载 jquery,lazyload.js 调用的demo
    一、Spring的第一个课时
    线程的基本了解
    HTTPS/HTTP监听常见问题
    Leetcode 118 杨辉三角
    HashSet的源码解释
    HashMap源码理解
  • 原文地址:https://www.cnblogs.com/CLGYPYJ/p/6899003.html
Copyright © 2020-2023  润新知