BZOJ1257【数论】

来源:互联网 发布:c语言计算三角函数 编辑:程序博客网 时间:2024/06/05 09:17
/* I will wait for you */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <algorithm>#include <iostream>#include <fstream>#include <vector>#include <queue>#include <deque>#include <set>#include <map>#include <string>#define make make_pair#define fi first#define se secondusing namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> pii;const int maxn = 100010;const int maxm = 1010;const int maxs = 26;const int inf = 0x3f3f3f3f;const int P = 1000000007;const double error = 1e-9;inline int read(){int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9')  f = (ch == '-' ? -1 : 1), ch = getchar();while (ch >= '0' && ch <= '9')   x = x * 10 + ch - '0', ch = getchar();return x * f;}ll ans;ll sum(int num){return (ll) num * (num + 1) / 2;}ll work(int n, int k){int m = min(n, k);ll ans = (ll) m * k;for (int i = 1, pos; i <= m; i = pos + 1) {pos = min(k / (k / i), m);ans -= (ll) (sum(pos) - sum(i - 1)) * (k / i);}ans += (ll) max(0, n - m) * k; return ans;}int main(){int n = read(), k = read();printf("%lld\n", work(n, k));return 0;}

0 0
原创粉丝点击