BZOJ 1257 [CQOI2007]余数之和sum ——Dirichlet积
生活随笔
收集整理的這篇文章主要介紹了
BZOJ 1257 [CQOI2007]余数之和sum ——Dirichlet积
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
【題目分析】
? ? 卷積很好玩啊。
?
【代碼】
#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_JUDGEfreopen("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; }
轉(zhuǎn)載于:https://www.cnblogs.com/SfailSth/p/6287519.html
總結(jié)
以上是生活随笔為你收集整理的BZOJ 1257 [CQOI2007]余数之和sum ——Dirichlet积的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 幡然醒悟
- 下一篇: JS校验身份证号码的有效性