Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <algorithm>
  6. #include <cassert>
  7. #include <map>
  8. #include <iomanip>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <unordered_map>
  12. #include <set>
  13. #include <functional>
  14.  
  15.  
  16. using namespace std;
  17. using ll = long long;
  18.  
  19.  
  20. #define SZ(a) a.size()
  21. #define pb(a) push_back(a)
  22. #define ALL(a) a.begin(), a.end()
  23. #define mp(a,b) make_pair(a,b)
  24.  
  25. int gcd(int a, int b)
  26. {
  27. if (b == 0)
  28. {
  29. return a;
  30. }
  31. return gcd(b, a% b);
  32. }
  33.  
  34. int main() {
  35. ifstream cin("input.txt");
  36. int n;
  37. cin >> n;
  38. vector <vector<int>> c(n+1,vector<int> (0,0));
  39. for (int i = 1; i <= n; i++)
  40. {
  41. for (int j = 1; j <= n; j++)
  42. {
  43. if (gcd(i, j) == 1)
  44. {
  45. c[i].pb(j);
  46. }
  47. }
  48. }
  49. ll ans = 0;
  50. for (int i = 1; i <= n; i++)
  51. {
  52. sort(c[i].begin(), c[i].end());
  53. }
  54. for (int a = 1;a <= n; a++)
  55. {
  56. int pos = lower_bound(c[a].begin(), c[a].end(), a) - c[a].begin();
  57. for (int j = pos; j < c[a].size(); j++)
  58. {
  59. int cnt = 0;
  60. int b = c[a][j];
  61. int it1=0, it2 = 0;
  62. it1 = pos;
  63. while (it1 < c[a].size() && it2 < c[b].size() && c[b][it2] <= b)
  64. {
  65. if (c[a][it1] == c[b][it2])
  66. {
  67. if (a + c[a][it1] > b)
  68. {
  69. //cout << a << " " << c[b][it2] << " " << b << '\n';
  70. cnt++;
  71. }
  72. it1++;
  73. it2++;
  74. continue;
  75. }
  76. if (c[a][it1] < c[b][it2])
  77. {
  78. it1++;
  79. }
  80. else
  81. {
  82. it2++;
  83. }
  84.  
  85. }
  86. ans += cnt;
  87. }
  88. }
  89. cout << ans;
  90. //system("pause");
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement