TopCoder problem "FirstToLast" used in TCO06 Round 1 (Division I Level Two)



Problem Statement

    We can rotate a positive integer by removing its leftmost digit and attaching it on the right end. Return the smallest positive value with no leading zeros such that rotating it is the same as multiplying it by p/q. If no such value exists less than 2000000000 (2 billion), return -1.
 

Definition

    
Class:FirstToLast
Method:getSmallest
Parameters:int, int
Returns:int
Method signature:int getSmallest(int p, int q)
(be sure your method is public)
    
 

Notes

-After rotating, the number may have leading zeros.
-Rotating a value less than 10 does not change it.
 

Constraints

-p and q will each be between 1 and 100 inclusive.
 

Examples

0)
    
1
1
Returns: 1
1)
    
1
4
Returns: 102564
2)
    
1
6
Returns: -1
3)
    
1
100
Returns: 100
4)
    
92
10
Returns: -1

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6054

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9917&pm=6054

Writer:

AdminBrett

Testers:

PabloGilberto , lbackstrom , Olexiy

Problem categories:

Math