• BZOJ 1257 [CQOI2007]余数之和sum ——Dirichlet积


    【题目分析】

        卷积很好玩啊。

    【代码】

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstdlib>
    
    #include <map>
    #include <set>
    #include <queue>
    #include <string>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    #define maxn 500005
    #define ll long long
    #define inf 0x3f3f3f3f
    #define F(i,j,k) for (int i=j;i<=k;++i)
    #define D(i,j,k) for (int i=j;i>=k;--i)
    
    void Finout()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("wa.txt","w",stdout);
        #endif
    }
    
    int Getint()
    {
        int x=0,f=1; char ch=getchar();
        while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
        while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
        return x*f;
    }
    
    int n,k,r,l;
    ll ans=0;
    
    int main()
    {
        Finout();
        n=Getint(); k=Getint();
        ans=(ll)n*(ll)k;
    //    cout<<"ans  is "<<ans<<endl;
    	int now=1; r=min(n,k);
        while (r)
        {
        	now=k/r;
    //    	cout<<now<<" "<<n<<" "<<k<<" "<<r<<endl;
        	l=k/(now+1)+1;
    //    	cout<<"now "<<now<<endl;
    //    	cout<<l<<"---"<<r<<endl;
        	ans-=((ll)r+(ll)l)*((ll)r-(ll)l+1)/2LL*(ll)now;
    //    	cout<<"ans is "<<ans<<endl;
        	r=l-1;
    //    	cout<<"r is "<<r<<endl;
    	}
    	cout<<ans<<endl;
    }
    

      

  • 相关阅读:
    eclipse控制台出现中文乱码的问题
    运行jar包
    [MongoDB]------windos下的安装部署与基础使用
    SQLMap-----初识
    序言(第一次写随笔,怎么才能装成经常写的样子呢)
    php7.4编译(centos)
    NGINX 2
    NGINX 1
    LVS的DR模式与NET模式的负载均衡实验
    命令在线查询
  • 原文地址:https://www.cnblogs.com/SfailSth/p/6287519.html
Copyright © 2020-2023  润新知