Title Description
Given a positive integer n and k, calc j (n, k) = k mod 1 + k mod 2 + k mod 3 + ... + k mod n in
where MOD k i represents the remainder of i divided by k.
For example j (5, 3) = 3 mod 1 + 3 mod 2 + 3 mod 3 + 3 mod 4 + 3 mod 5 = 0 + 1 + 0 + 3 + 3 = 7Entry
Only the input line, comprising two integers n, k.
1 <= n, k <= 10 ^ 9Export
Output only one row, i.e., j (n, k).Sample input
5 3
Sample Output
7
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,k,ans; int main() { scanf("%lld%lld",&n,&k); ans=n*k; for (ll l=1,r=0; l<=n; l=r+1) { if (k/l) { r=min(n,k/(k/l)); } else { r=n; } ans-=(k/l)*(r-l+1)*(l+r)>>1; } printf("%lld\n",ans); }
Apart from the number and
Guess you like
Origin www.cnblogs.com/Accpted/p/11334370.html
Recommended
Ranking