BZOJ1257【数论】

/* 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 second

using 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;
}

你可能感兴趣的:(BZOJ1257【数论】)