您的位置:首页 > 其它

1363 - Joseph's Problem

2017-04-26 22:34 267 查看
1363 - Joseph's Problem

点击打开链接

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
typedef long long ll;
using namespace std;

ll cal(ll n, ll k) {
ll ans = 0;
if (n > k)
ans += (n-k) * k;
ll a = (ll) sqrt(k), b = k / a;
for (ll i = a; i > 1; i--) {
ll a0 = k / i, an = k / (i-1);
if (a0 > n)
break;
if (an > n)
an = n;
ans += (k % an + k % (a0 + 1)) * (an - a0) / 2;
}
for (int i = 1; i <= n && i <= b; i++)
ans += k % i;
return ans;
}

int main() {
ll n, k;
while (scanf("%lld%lld", &n, &k) != EOF) {
printf("%lld\n", cal(n, k)) ;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: