1.余数之和 #include <iostream> #include <cstring> #include <algorithm> using namespace std; #define int long long signed main() { int n,k; cin>>n>>k; int res=n*k; for(int l=1,r;l<=n;l=r+1) { if(k/l==0)break; r=min(k/(k/l),n); res-=(k/l)*(l+r)*(r-l+1)/2; } cout<<res<<'\n'; } 2.区间最大值 #include<iostream> #include<cstring> #include<algorithm> using namespace std; const int N = 100010; #define int long long int n,m; signed main() { cin>>n>>m; int L,R; while(m--) { cin>>L>>R; int res=0; for(int l=L,r;l<=R;l=r+1) { res=max(res,n-(n/l)*l); r=min(R,n/(n/l)); } cout<<res<<'\n'; } }