407430: GYM102788 H Exam

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Examtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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$$$:

  1. Add $$$1$$$ to the current value
  2. Add integer $$$x$$$ to the current value ($$$x > 1$$$)
  3. 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$$$.

Input

The 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.

Output

The 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.

ExamplesInput
7 4
Output
5
Input
14 3
Output
0

加入题单

上一题 下一题 算法标签: