Connection Status:
Competition Arena > MicroStrings
SRM 614 · 2013-12-22 · by Cricicle · Brute Force, Simulation
Class Name: MicroStrings
Return Type: String
Method Name: makeMicroString
Arg Types: (int, int)
Problem Statement

Problem Statement

John couldn't handle long strings so he came up with the idea of MicroStrings.


You are given two positive ints: A and D. These determine an infinite decreasing arithmetic progression: A, A-D, A-2D, and so on. Clearly, only finitely many elements of such a progression are non-negative.


Each such progression defines one MicroString, as follows: You take all the non-negative elements, convert each of them into a string, and then concatenate those strings (in order).


For example, let A=12 and D=5. For these values we get the arithmetic progression (12, 7, 2, -3, -8, ...). The non-negative elements are 12, 7, and 2. The corresponding strings are "12", "7", and "2". Their concatenation is the following MicroString: "1272".


Given A and D, return the MicroString they define.

Notes

  • When converting a number to a string, the string must not have unnecessary leading zeros.

Constraints

  • A will be between 1 and 200, inclusive.
  • D will be between 1 and 200, inclusive.
Examples
0)
12
5
Returns: "1272"

This is the example from the problem statement.

1)
3
2
Returns: "31"
2)
31
40
Returns: "31"
3)
30
6
Returns: "3024181260"

The number 0 is also non-negative. When we convert it into a string, we get the string "0".

4)
1
1
Returns: "10"

Submissions are judged against all 63 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class MicroStrings with a public method string makeMicroString(int A, int D) · 63 test cases · 2 s / 256 MB per case

Submitting as anonymous