整除分块板子

#include
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll zcfk(ll n,ll k) {
	if(k>=n) {
		ll cut=0;
		for(ll l=2,r; l<=n; l=r+1) {
			r=n/(n/l);
			cut=(cut+1ll*(r-l+1)*(n/l)%mod)%mod;
		}
		return cut;
	} else {
		ll cut=0;
		for(ll l=2,r; l<=k; l=r+1) {
			r=min(n/(n/l),k);
			cut=(cut+1ll*(r-l+1)*(n/l)%mod)%mod;
		}
		return cut;
	}
}
int main() {
	ll n,k;
	scanf("%lld %lld",&n,&k);
	ll ans=0;
	ans=(ans+zcfk(n,k))%mod;
	ans=(ans+zcfk(n-1,k))%mod;
	ans=(ans+(n-1))%mod;
	ans=(ans+k)%mod;
	printf("%lld\n",ans);
	return 0;
}


你可能感兴趣的:(数论与数学)