fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. const int n = 10000;
  7. const int m = 5;
  8. const int N = n * (n - 1) / 2;
  9.  
  10. long long d[N];
  11. int p[N], q[N], s[n];
  12.  
  13. void MergeColumns(int l, int r, bool ptoq)
  14. {
  15. int c = (l + r) / 2;
  16. if (c - l > 1) MergeColumns(l, c, !ptoq);
  17. if (r - c > 1) MergeColumns(c, r, !ptoq);
  18.  
  19. int L = s[l], C = s[c], R = s[r];
  20. int *S = ptoq ? p : q, *D = ptoq ? q : p;
  21. merge(S + L, S + C, S + C, S + R, D + L, [](int x, int y) {return d[x] < d[y];});
  22. }
  23.  
  24. int main(void)
  25. {
  26. int a, b, i, j;
  27.  
  28. for (s[i = 0] = 0, b = 1; b <= n - 1; b++) {
  29. for (a = b + 1; a <= n; a++, i++) {
  30. d[i] = (long long)a * a * a - (long long)b * b * b;
  31. p[i] = q[i] = i;
  32. }
  33. s[b] = i;
  34. }
  35. MergeColumns(0, n - 1, false);
  36.  
  37. for (i = 0; i < N - m + 1; i++) {
  38. if (d[p[i]] != d[p[i + m - 1]]) continue;
  39.  
  40. cout << d[p[i]] << ": ";
  41. for (j = i + m; d[p[j]] == d[p[i]]; j++);
  42. for_each(p + i, p + j, [&](int &x) {
  43. b = upper_bound(s + 1, s + n, x) - s;
  44. a = x - s[b - 1] + b + 1;
  45. cout << (&x > p + i ? ", (" : "(") << a << ", " << b << ")";
  46. });
  47. cout << endl;
  48. i = j - 1;
  49. }
  50. return 0;
  51. }
Success #stdin #stdout 3.95s 784644KB
stdin
Standard input is empty
stdout
1412774811: (1134, 357), (1155, 504), (1246, 805), (2115, 2004), (4746, 4725)
11302198488: (2268, 714), (2310, 1008), (2492, 1610), (4230, 4008), (9492, 9450)