When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

afaki's blog

By afaki, history, 7 years ago, In English
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

First let's solve case with length 2. a*B + a = N <=> a*(B + 1) = N, it means that multipliers are divisors of N, so you need check all of them. Calculate primes up to sqrt(10^14), factorise N using them and recursively build all divisors, check them for correctness. Then solve case with length >= 4. It is easy to prove B in that case is < N^(1/3), so you can check all B up to it.