TopcoderArchiveVisit Topcoder
SRM2 Feb 2008
SRM 390

ConcatenateNumber

Problem statement, definition, constraints, and public examples.

Problem Statement

Given a positive integer number, concatenate one or more copies of number to create an integer that is divisible by k. Do not add any leading zeroes. Return the least number of copies needed, or -1 if it is impossible.

Definition

Class:
ConcatenateNumber
Method:
getSmallest
Parameters:
int, int
Returns:
int
Method signature:
int getSmallest(int number, int k)
(be sure your method is public)

Constraints

  • number will be between 1 and 1,000,000,000, inclusive.
  • k will be between 1 and 100,000, inclusive.

Examples

  1. 2
    9
    Returns: 9
    At least 9 copies are needed, since 222222222 is divisible by 9.
  2. 121
    11
    Returns: 1
    121 is divisible by 11.
  3. 1
    2
    Returns: -1
    You can never get an even number by concatenating only 1's.
  4. 35
    98765
    Returns: 9876
    The resulting integer could be really big.
  5. 1000000000
    3
    Returns: 3
Back to all problems