TopcoderARCHIVE
Archive/Problems/ThreeDigits
SRM · Problem 16246

ThreeDigits

Problem statement, definition, constraints, and public examples.

Problem Statement

Find the last three digits before the decimal point and the first three digits after the decimal point in the number XY / Z.

Return your answer formatted as a String. The String must always include the decimal point and exactly three digits after the decimal point. If the number has fewer than three digits before the decimal point, only include those digits, do not pad the number with zeros.

Definition

Class:
ThreeDigits
Method:
calculate
Parameters:
int, int, int
Returns:
String
Method signature:
String calculate(int X, int Y, int Z)
(be sure your method is public)

Notes

  • Do not perform any rounding, just output the correct digits in the required places. E.g., if the exact number is 123.4567, the correct output is "123.456", not "123.457".
  • For numbers with finite decimal expansions we are using the more natural form where all the following digits are zeros. For example, if the exact number is 123.4, only "123.400" is a correct answer, "123.399" (as a prefix of 123.9999999...) will be rejected.

Constraints

  • X will be between 0 and 1000000000 (1 billion).
  • Y will be between 0 and 1000000000 (1 billion).
  • Z will be between 1 and 1000000 (1 million).
  • Either X or Y will be non-zero.

Examples

  1. 3
    5
    7
    Returns: "34.714"
    In this example, since the value of XY / Z = 243 / 7 = 34.7142857..., you should return "34.714".
  2. 4
    7
    32
    Returns: "512.000"
    In this example, since the value of XY / Z = 16384 / 32 = 512.0000000..., you should return "512.000".
  3. 3
    2
    36
    Returns: "0.250"
    In this example, since the value of XY / Z = 9 / 36 = 0.2500000..., you should return "0.250". Note that the "0" before the decimal point is mandatory, the return value ".250" will be rejected.
  4. 7
    4
    47
    Returns: "51.085"
    In this example, since the value of XY / Z = 2401 / 47 = 51.0851063..., you should return "51.085".
  5. 13
    6
    479
    Returns: "076.845"
    13^6 / 479 = 10076.84551148..., so the correct answer is "076.845". Note that this number has more than three digits before its decimal point, so the return value must start "076" and not just "76".
  6. 1234
    56789
    123456
    Returns: "133.942"
    The value of 123456789 / 123456 has 175,548 digits before the decimal point. The number begins 4028022093412... and around its decimal point we have the digits ...7339915133.9429756350...
  7. 999999999
    128
    1000000
    Returns: "000.000"
    In this example, both of the last three digits before the decimal point and the first three digits after the decimal point are "000", even though the value is not an integer.
← All problems