Back
Close

Shawn & Gus are lucky with digits

Statement

 Goal

Shawn has found two digits A and B (1<=A<=9 and 1<=B<=9). He decides to do something silly with them.
He asks Gus to find the smallest integer N such that the two following conditions hold :
1) the decimal representation of N ends with A (e.g. if A is 5, then N must be something like ".....5")
2) let M be the new number made by removing the digit A from the end of the decimal representation of N and putting it a the beginning (*). Then we must have M=B*N

(*) Formally if the decimal representation of N is D1 D2 D3 D4 ...Dk, then the decimal representation of M is Dk D1 D2 ...D(k-1)

Note: In this version of the problem, Gus and Shawn are very lucky, so A and B are chosen in such a way that a solution exists, with less than 9 digits.
Input
Line 1: Integer A
Line 2: Integer B
Output
Line 1: The smallest Integer N satisfying the required conditions
Constraints
1<=A<=9
1<=B<=9
Example
Input
7
4
Output
179487

Game modes

Test cases
Test 1 Test
Input
7 4
Output
179487

Validator 1 Validator
Input
6 4
Output
153846

Test 2 Test
Input
1 1
Output
1

Validator 2 Validator
Input
2 1
Output
2

Test 3 Test
Input
5 4
Output
128205

Validator 3 Validator
Input
9 4
Output
230769

Test 4 Test
Input
7 5
Output
142857

Validator 4 Validator
Input
4 4
Output
102564

Solution language

Solution

Stub generator input