Circular Numbers

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 16M

Problem type

An (XY, D)-CIRCULAR NUMBER is a number whose last two digits are X and Y, and multiplication of the number by the single digit D is equivalent to moving the last two digits (XY) to the beginning of the number. For example, the number 132832080200501253 is a (53, 4)-CIRCULAR NUMBER because 132832080200501253 \times 4 = 531328320802005012. Write a program that asks for a two-digit number XY and a single digit D, and prints the smallest (XY, D)-CIRCULAR NUMBER or prints a message NONE if none exists. It is guaranteed that your number will not exceed 255 digits.

Input Specification

An integer number, N, indicating the total number of cases. On each of the next N lines are the two-digit number XY and the single digit D, separated by a space.

Output Specification

The smallest circular number (if one exists with less than 255 digits) that satisfies the given condition; otherwise output the message NONE.

Sample Input

1
53 4

Sample Output

132832080200501253

Comments


  • 0
    d  commented on Aug. 9, 2022, 7:07 a.m. edit 2
    • 10 \le XY \le 99 and 2 \le D \le 9
    • The circular number can have leading zeroes.
    • If you test beyond 255 digits, you will get WA. In some test cases, the smallest answer exceeds 255 digits.