zoukankan      html  css  js  c++  java
  • hdu 5212 反向容斥或者莫比

    http://acm.hdu.edu.cn/showproblem.php?pid=5212

    题意:忽略。。

    题解:把题目转化为求每个gcd的贡献。(http://www.cnblogs.com/z1141000271/p/7419717.html 和这题类似 反向容斥)这里先用容斥写了,mobious的之后再说吧23333。

    然后比较想说的是这个调和级数的复杂度 nlog(n)

    ac代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <algorithm>
    #define mt(a) memset(a,0,sizeof(a))
    using namespace std;
    const int mod=10007;
    typedef long long ll;
    ll a[10001];
    ll num[10001];
    ll cnt[10001];
    ll get(ll n)
    {
        int f=1;
        f=n*n;
        f%=mod;
        return f;
    }
    int main()
    {
        ll n;
        while(~scanf("%lld",&n))
        {
            ll mx=-100;
            mt(a);
            mt(cnt);
            mt(num);
            for(int i=1;i<=n;i++)
            {
                scanf("%lld",&a[i]);
                num[a[i]]++;
                mx=max(mx,a[i]);
            }
            ll ans=0;
            for(ll i=mx;i>=2;i--)
            {
                int ret=num[i];
                for(int j=i*2;j<=mx;j+=i)
                {
                    cnt[i]=(cnt[i]-cnt[j]+mod)%mod;
                    ret+=num[j];
                }
               // cout<<ret<<endl;
                cnt[i]+=get(ret);//想清楚。
                cnt[i]+=mod;
                cnt[i]%=mod;
                ll p=i*(i-1)%mod;
                ans=(ans+(cnt[i]*p))%mod;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Zepto源码分析-动画(fx fx_method)模块
    CSS3用法理解
    移动端网页meta设置和响应式
    javascript基础-正则表达式
    net core 2.x
    angular
    .net core 2.x
    .net core 2.x
    DDD
    DDD
  • 原文地址:https://www.cnblogs.com/z1141000271/p/7419896.html
Copyright © 2011-2022 走看看