UVA1363Joseph'sProblem

来源:互联网 发布:软件开发工资 北京 编辑:程序博客网 时间:2024/05/29 05:53
//UVA1363Joseph'sProblem#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;int main() {int n, k;while(scanf("%d%d", &n, &k) == 2) {    LL ans = 0;        for(int i = 1; i <= n; i++) {            int p = k / i;//1int q = k % i;//1int cnt = n - i;//1if(p > 0) cnt = min(cnt, q / p);//计算除了首项之外还剩下的项数 LL sum = (LL)(2 * q - cnt * p) * (cnt + 1) / 2;//小学必备高斯公式 ans += sum;i += cnt;}printf("%lld\n", ans);}return 0;}/*5 3*/