fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <memory.h>
  4.  
  5. using namespace std;
  6.  
  7. const int n = 5000;
  8. const int m = 5;
  9. const int N = n * (n - 1) / 2;
  10.  
  11. constexpr int SelectDivisor(void)
  12. {
  13. int d = 0, i = 0, r[n + 100] = {0};
  14.  
  15. for (d = n + 1; d < end(r) - r; d++) {
  16. for (i = 1; i < end(r) - r; i++) r[i] = 0;
  17. for (i = 1; i <= n; i++) if (r[(long long)i * i * i % d]++) break;
  18. if (i > n) break;
  19. }
  20. return d;
  21. };
  22.  
  23. const int D = SelectDivisor();
  24.  
  25. int s[n];
  26. int P[D][n], Q[D][n];
  27. int C[D];
  28. int T[n];
  29.  
  30. int main(void)
  31. {
  32. int a, b, i, j, q, r;
  33.  
  34. memset(C, 0, sizeof(C));
  35. for (s[i = 0] = 0, b = 1; b <= n - 1; b++) {
  36. for (a = b + 1; a <= n; a++, i++) {
  37. long long d = (long long)a * a * a - (long long)b * b * b;
  38. q = d / D;
  39. r = d % D;
  40. P[r][C[r]] = i;
  41. Q[r][C[r]] = q;
  42. C[r]++;
  43. }
  44. s[b] = i;
  45. }
  46.  
  47. for (r = 0; r < D; r++) {
  48. memcpy(T, Q[r], sizeof(*T) * C[r]);
  49. sort(T, T + C[r]);
  50. for (i = 0; i < C[r]; i++) {
  51. if (T[i] != T[i + m - 1]) continue;
  52.  
  53. cout << (long long)T[i] * D + r << ": ";
  54. bool first = true;
  55. for (j = 0; j < C[r]; j++) {
  56. if (Q[r][j] != T[i]) continue;
  57. int x = P[r][j];
  58. b = upper_bound(s + 1, s + n, x) - s;
  59. a = x - s[b - 1] + b + 1;
  60. if (first) first = false; else cout << ", ";
  61. cout << "(" << a << ", " << b << ")";
  62. }
  63. cout << endl;
  64. for (j = i + m; T[j] == T[i]; j++);
  65. i = j - 1;
  66. }
  67. }
  68. return 0;
  69. }
Success #stdin #stdout 0.63s 198644KB
stdin
Standard input is empty
stdout
1412774811: (1134, 357), (1155, 504), (1246, 805), (2115, 2004), (4746, 4725)