407430: GYM102788 H Exam
Description
A student named Vasily had to solve the following problem during his Unified State Exam in Computer Science.
Executor $$$A17$$$ works with three commands numbered $$$1$$$ through $$$3$$$:
- Add $$$1$$$ to the current value
- Add integer $$$x$$$ to the current value ($$$x > 1$$$)
- Multiply the current value by $$$7$$$.
The first command adds $$$1$$$ to the number on the screen, the second one adds $$$x$$$, and the third one multiplies it by $$$7$$$.
Program for Executor $$$A17$$$ contain a sequence of commands numbered $$$1$$$ through $$$3$$$. Executor $$$A17$$$ transforms the number on the screen in accordance with the given sequence of commands. The first value is always $$$1$$$. The final result of running the program is $$$N$$$.
After pondering on the subject for a while, Vasily calculated the value of $$$K$$$ – number of program options for Executor $$$A17$$$ resulting in a certain number $$$N$$$. For example, when $$$x = 5, N = 7$$$, the number of options $$$K = 4$$$ (numbers of commands):
- 1, 1, 1, 1, 1, 1;
- 2, 1;
- 1, 2;
- 3.
After the exam, Vasily started wondering how to calculate the number $$$x$$$ based on input data $$$N$$$ and $$$K$$$.
Write a program that will determine the smallest number x meeting the problem's requirements based on given numbers $$$N$$$ and $$$K$$$.
InputThe first line of the input file contains two positive integers $$$N$$$ and $$$K$$$ ($$$0 < N \le 10^4, 0 < K \le 2^{60}$$$) separated by a space.
OutputThe output file must contain a single number $$$x$$$ ($$$1 < x < N$$$) – the smallest possible number meeting the requirements, if such number exists, otherwise output file must contain 0.
ExamplesInput7 4Output
5Input
14 3Output
0