T3000

Untitled

Jan 12th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     long long a;
  8.     while (true)
  9.     {
  10.         cin >> a;
  11.         if (a == 0)
  12.         {
  13.             return 0;
  14.         }
  15.         if (a < 3)
  16.         {
  17.             cout << "No such base" << '\n';
  18.             continue;
  19.         }
  20.  
  21.         if (a == 3)
  22.         {
  23.             cout << 4 << '\n';
  24.             continue;
  25.         }
  26.         long long x1, x2, r = 9999999;
  27.  
  28.         x1 = a - 3;
  29.         for (int i = 2; i * i <= x1; i++)
  30.         {
  31.             if (x1 % i == 0)
  32.             {
  33.                 x2 = x1 / i;
  34.                 if (i > 3 && i < r)
  35.                 {
  36.                     r = i;
  37.                 }
  38.                 else if (x2 > 3 && x2 < r)
  39.                 {
  40.                     r = x2;
  41.                 }
  42.             }
  43.         }
  44.  
  45.         if (r == 9999999)
  46.         {
  47.             r = x1;
  48.         }
  49.         cout << r << '\n';
  50.     }
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment