zoukankan      html  css  js  c++  java
  • BZOJ 2005 [Noi2010]能量采集 ——Dirichlet积

    【题目分析】

        卷积一卷。

        然后分块去一段一段的求。

        O(n)即可。

    【代码】

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define maxn 100005 
    #define ll long long
    #define F(i,j,k) for (ll i=j;i<=k;++i)
    ll n,m,pr[maxn],top,d;
    ll phi[maxn];
     
    void init()
    {
        F(i,2,maxn-1)
        {
            if (!phi[i]) pr[++top]=i,phi[i]=i-1;
            for (ll j=1;j<=top&&(ll)pr[j]*i<(ll)maxn;++j)
            {
                if (i%pr[j]==0) {phi[i*pr[j]]=phi[i]*pr[j];break;}
                else phi[i*pr[j]]=phi[i]*phi[pr[j]];
            }
        }
    }
     
    int main()
    {
        init();
        scanf("%d%d",&n,&m);
        F(i,1,maxn-1) phi[i]+=phi[i-1];
        ll ans=0;
        ll la,lb,nowa,nowb,l,r=n;
        while (r)
        {
            nowa=n/r; nowb=m/r;
            la=n/(nowa+1)+1;lb=m/(nowb+1)+1;
            l=max(la,lb);
            ans+=(ll)nowa*nowb*(phi[r]-phi[l-1]);
            r=l-1;
        }
        printf("%lld
    ",n*m+2*ans);
    }
    

      

  • 相关阅读:
    webform传值
    webform控件以及使用
    SQL Server 基本数据类型
    数据库设计三大范式
    第一阶段考试
    弹出层
    三级联动日期选择
    DOM例题
    JS方法
    DOM
  • 原文地址:https://www.cnblogs.com/SfailSth/p/6435474.html
Copyright © 2011-2022 走看看