HZAU 1001 Handing Out Candies

原题
这题还是蛮难的 值得细细品味

#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
using namespace std;
void solve()
{
  long long n, k;
  cin >> n >> k;
  long i = k / n;
  long l = k / (i + 1) + 1;
  long r = n;
  long long ans = 0;
  while (l > 0) {
    ans += (k * (r - l + 1) - i * (l + r) * (r - l + 1) / 2);
    if (l == 1) break;
    i = k / (l - 1);
    l = k / (i + 1) + 1;
    r = k / i;
  }
  cout << ans << endl;
}
int main()
{
// freopen("input.txt", "r", stdin);
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    solve();
  }
}

你可能感兴趣的:(HZAU 1001 Handing Out Candies)