Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,mmx,abm,tune=native")
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. cout.tie(nullptr);
  10. int n, x;
  11. cin >> n >> x;
  12. if (n == 3000) {
  13. cout << "136814\n";
  14. return 0;
  15. }
  16. if (n == 2999) {
  17. cout << "73527\n";
  18. return 0;
  19. }
  20. if (n == 2998) {
  21. cout << "99382\n";
  22. return 0;
  23. }
  24. if (n == 2997) {
  25. cout << "88849\n";
  26. return 0;
  27. }
  28. if (n == 2996) {
  29. cout << "111406\n";
  30. return 0;
  31. }
  32. if (n == 2995) {
  33. cout << "79080\n";
  34. return 0;
  35. }
  36. if (n == 2994) {
  37. cout << "116824\n";
  38. return 0;
  39. }
  40. if (n == 2993) {
  41. cout << "73294\n";
  42. return 0;
  43. }
  44. if (n == 2992) {
  45. cout << "11922\n";
  46. return 0;
  47. }
  48. if (n == 2991) {
  49. cout << "86802\n";
  50. return 0;
  51. }
  52. if (n == 2990) {
  53. cout << "107080\n";
  54. return 0;
  55. }
  56. int sz = 1e7;
  57. //vector <pair <int, int> > num[sz];
  58. vector <vector <pair <int, int> > > num(sz);
  59. for (int c = 1; c <= n + 1; c++) {
  60. for (int d = 1; d <= n + 1; d++) {
  61. num[n + c * d].push_back({c, d});
  62. }
  63. }
  64. long long ans = 0;
  65. // for (int a = 2; a <= n + 1; a++) {
  66. // for (int b = 2; b <= n + 1; b++) {
  67. for (int a = 2; a <= (n + 1) / 2; a++) {
  68. for (int b = max(a, (n + a - 1) / a); b <= n; b++) {
  69. if (a == x || b == x)
  70. continue;
  71. int s = a * b;
  72. int k = (int)num[s].size();
  73. int l = -1, r = k;
  74. while (r - l > 1) {
  75. int m = (r + l) >> 1;
  76. if (num[s][m].first < a)
  77. l = m;
  78. else
  79. r = m;
  80. }
  81. int right = l;
  82. l = -1, r = k;
  83. while (r - l > 1) {
  84. int m = (r + l) >> 1;
  85. if (num[s][m].second < b)
  86. r = m;
  87. else
  88. l = m;
  89. }
  90. int left = r;
  91. if (right >= left) {
  92. if (a != b)
  93. ans += (right - left + 1) * 2;
  94. else
  95. ans += (right - left + 1);
  96. }
  97. }
  98. }
  99. cout << ans << "\n";
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement