Advertisement
ivnikkk

Untitled

Jan 18th, 2023
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "bits/stdc++.h"
  3. using namespace std;
  4. #define all(a) a.begin(), a.end()
  5. #define int long long
  6. const int inf = LLONG_MAX;
  7. signed main() {
  8. #ifdef _DEBUG
  9.     freopen("input.txt", "r", stdin);
  10.     freopen("output.txt", "w", stdout);
  11. #endif
  12.     //a[i] / x = (1 + x)^(i - 2)
  13.     int m; cin >> m;
  14.     int res = 2;
  15.     auto try_solve = [&](int x) {
  16.         int d = m / x;
  17.         int y = 1;
  18.         int cnt = 2;
  19.         while (1) {
  20.             if (d % (1 + x) == 0) {
  21.                 d /= (1 + x);
  22.                 cnt++;
  23.             }
  24.             else {
  25.                 break;
  26.             }
  27.         }
  28.         return cnt;
  29.     };
  30.     for (int i = 2; i * i * i <= m; i++) {
  31.         if (m % i == 0) {
  32.             res = max({ res, try_solve(m / i), try_solve(i) });
  33.         }
  34.     }
  35.     int tl = 0, tr = (int)sqrt(m) + 1;
  36.     while (tr - tl > 1) {
  37.         int tm = (tr + tl) / 2;
  38.         if (tm * (tm + 1) >= m) {
  39.             tr = tm;
  40.         }
  41.         else {
  42.             tl = tm;
  43.         }
  44.     }
  45.     if (tr * (tr + 1) == m) {
  46.         res = max(res, 3ll);
  47.     }
  48.     cout << res << '\n';
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement