Dang_Quan_10_Tin

PAIRLCM TS10 PTNK 2020-2021

Jan 5th, 2022 (edited)
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #define task "PAIRLCM"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. using ll = long long;
  10. using ld = long double;
  11.  
  12. constexpr int N = 1e5 + 5;
  13. int n;
  14.  
  15. void Read()
  16. {
  17.     cin >> n;
  18. }
  19.  
  20. bool IsOdd(int v)
  21. {
  22.     return v & 1;
  23. }
  24.  
  25. ll lcm(int x, int y)
  26. {
  27.     return 1ll * x * y / __gcd(x, y);
  28. }
  29.  
  30. void Solve()
  31. {
  32.     if (IsOdd(n))
  33.         cout << 1ll * (n / 2) * (n / 2 + 1);
  34.     else
  35.     {
  36.         ll v = n / 2;
  37.         if (n / 2 > 1)
  38.             v = max(v, lcm(n / 2 - 1, n / 2 + 1));
  39.         if (n / 2 > 2)
  40.             v = max(v, lcm(n / 2 - 2, n / 2 + 2));
  41.  
  42.         cout << v;
  43.     }
  44. }
  45.  
  46. int32_t main()
  47. {
  48.     ios::sync_with_stdio(0);
  49.     cin.tie(0);
  50.     cout.tie(0);
  51.     if (fopen(task ".INP", "r"))
  52.     {
  53.         freopen(task ".INP", "r", stdin);
  54.         freopen(task ".OUT", "w", stdout);
  55.     }
  56.  
  57.     Read();
  58.     Solve();
  59. }
  60.  
Add Comment
Please, Sign In to add comment