zoukankan      html  css  js  c++  java
  • hdu 5212 Code 筛法或者莫比乌斯

    Code

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)



    Problem Description
    WLD likes playing with codes.One day he is writing a function.Howerver,his computer breaks down because the function is too powerful.He is very sad.Can you help him?

    The function:


    int calc
    {
      
      int res=0;
      
      for(int i=1;i<=n;i++)
        
        for(int j=1;j<=n;j++)
        
        {
          
          res+=gcd(a[i],a[j])*(gcd(a[i],a[j])-1);
          
          res%=10007;
        
        }
      
      return res;

    }
     
    Input
    There are Multiple Cases.(At MOST 10)

    For each case:

    The first line contains an integer N(1N10000).

    The next line contains N integers a1,a2,...,aN(1ai10000).
     
    Output
    For each case:

    Print an integer,denoting what the function returns.
     
    Sample Input
    5 1 3 4 2 4
     
    Sample Output
    64
    Hint
    gcd(x,y) means the greatest common divisor of x and y.
     
    Source

    先占坑,晚点补莫比乌斯

    #include<bits/stdc++.h>
    using namespace std;
    #define LL long long
    #define pi (4*atan(1.0))
    #define eps 1e-8
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=1e4+10,M=1e6+10,inf=1e9+10;
    const LL INF=1e18+10,mod=1e9+7;
    
    int cnt[N],sum[N];
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {
            memset(cnt,0,sizeof(cnt));
            memset(sum,0,sizeof(sum));
            for(int i=1;i<=n;i++)
            {
                int x;
                scanf("%d",&x);
                cnt[x]++;
            }
            for(int i=1;i<=10000;i++)
            {
                for(int j=i;j<=10000;j+=i)
                    sum[i]+=cnt[j];
                sum[i]=sum[i]*sum[i];
            }
            LL ans=0;
            for(int i=10000;i>=1;i--)
            {
                for(int j=i+i;j<=10000;j+=i)
                    sum[i]-=sum[j];
                //if(sum[i])cout<<i<<" "<<sum[i]<<endl;
                ans+=1LL*i*(i-1)*sum[i];
                ans%=10007;
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    YAML 语法小结
    小程序之脚本语言
    小程序WXML 使用小结
    微信小程序 js逻辑
    小程序开发1
    联想Y7000安装Ubuntu16.04/Win10双系统,wifi问题,显卡驱动和CUDA10安装
    VS2015中配置Eigen
    联想Y700安装显卡驱动和CUDA8.0
    php微信生成微信公众号二维码扫描进入公众号带参数
    Y7000 (1)安装ubuntu1604遇到的问题
  • 原文地址:https://www.cnblogs.com/jhz033/p/7496262.html
Copyright © 2011-2022 走看看