TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

FirstToLast

Problem statement, definition, constraints, and public examples.

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

  1. 1
    1
    Returns: 1
  2. 1
    4
    Returns: 102564
  3. 1
    6
    Returns: -1
  4. 1
    100
    Returns: 100
  5. 92
    10
    Returns: -1
Back to all problems