zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    Java 中字符串的格式化
    Awk学习笔记
    Spring任务调度实战之Quartz Simple Trigger
    Subclipse vs. Subversive
    使用OpenSSL生成自用证书
    httpclient处理页面跳转
    巧用TableDiff(转)
    DBCC了解页面结构
    取最新一条SQL优化
    SQL 2008 到 SQL2012的镜像
  • 原文地址:https://www.cnblogs.com/SfailSth/p/6287519.html
Copyright © 2011-2022 走看看