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;
}
点击打开链接
#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;
}
相关文章推荐
- UVA 1363 - Joseph's Problem(数论)
- uva 1363 - Joseph's Problem(数论)
- UVa 1363 POJ 2800 Joseph's Problem
- UVa1363 - Joseph's Problem(数论)
- UVA 1363 Joseph's Problem(数论)
- uva1363 Joseph's Problem
- uva 1363 Joseph's Problem 等差数列
- UVA - 1363 Joseph's Problem
- UVa 1363 Joseph's Problem
- UVA - 1363 Joseph's Problem(打表找规律)
- 1363 - Joseph's Problem
- POJ 2800 Joseph's Problem
- UVa 1363 (数论 数列求和) Joseph's Problem
- UVa1363 Joseph's Problem
- POJ 2800 Joseph's Problem 笔记
- ZOJ 2646 Joseph's Problem
- POJ 2800 Joseph's Problem(数论)
- POJ 2800 : Joseph\'s Problem (须仔细分析)
- UVa 1363 Joseph's Problem (数论)
- poj 2800 Joseph’s Problem(数论)