fork download
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. #define TASK "CGCD"
  7. #define Faster() cin.tie(0)->sync_with_stdio(0);
  8. #define gcd(x,y) __gcd(x,y)
  9. #define ii pair<int, int>
  10.  
  11. const int N = 1e7 + 5;
  12. const int M = 1e3 + 5;
  13. const int mod = 1e9 + 7;
  14.  
  15. int n, m;
  16. ll dp[N];
  17.  
  18. void Init() {
  19. cin >> n >> m;
  20. if(n > m) swap(n, m);
  21. }
  22. void Solve() {
  23. for(int i = 1; i <= n; ++i) {
  24. dp[i] = 1ll * (n / i) * (m / i);
  25. }
  26. for(int i = n; i >= 1; --i) {
  27. for(int j = i * 2; j <= n; j += i) dp[i] -= dp[j];
  28. }
  29. cout << dp[1];
  30. }
  31. signed main() {
  32. Faster();
  33. if(fopen(TASK".INP", "r")) {
  34. freopen(TASK".INP", "r", stdin);
  35. freopen(TASK".OUT", "w", stdout);
  36. }
  37. Init();
  38. Solve();
  39. }
  40.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty