TopcoderArchive
Archive
Algorithm problem

Reciprocal

Problem statement, definition, constraints, and public examples.

Problem Statement

Given integers x, d, and n, compute n consecutive digits of 1/x, beginning with digit d. Digit 1 refers to the tenths place, digit 2 to the hundredths place, etc. Return the digits as a String of length n.

For example, 1/7 equals 0.1428571428571428... If x is 7, d is 2, and n is 4, your method should return "4285".

Definition

Class:
Reciprocal
Method:
digits
Parameters:
int, int, int
Returns:
String
Method signature:
String digits(int x, int d, int n)
(be sure your method is public)

Constraints

  • x will be between 2 and 10000, inclusive.
  • d will be between 1 and 1000000000, inclusive.
  • n will be between 1 and 50, inclusive.

Examples

  1. 7
    2
    4
    Returns: "4285"
    This is the example from the problem statement.
  2. 10000
    1
    7
    Returns: "0001000"
  3. 3
    5000
    8
    Returns: "33333333"
  4. 9999
    9
    13
    Returns: "0001000100010"
  5. 7549
    50000
    1
    Returns: "0"
Back to all problems