标签:namespace pac 证明 alt style bsp https class include
题目链接:https://www.acwing.com/problem/content/201/
求k对1-n所有数取模的和。
证明一段可以作为等差数列来求,证明如下:(转自ACwing)
代码如下:
#include<iostream> using namespace std; typedef long long ll; int main(){ int n,k; cin>>n>>k; ll ans=n*k; for(int l=1,r=0;r<=n;r=l+1) { r=min(n,(int)k/(k/l)); ans-=1ll*(k/l)*(l+r)*(r-l+1)/2; } cout<<ans<<endl; }
标签:namespace pac 证明 alt style bsp https class include
原文地址:https://www.cnblogs.com/randy-lo/p/13179325.html