Connection Status:
Competition Arena > SpecialSquare
2022 HF Final · 2022-03-16 · by misof · Math
Class Name: SpecialSquare
Return Type: String
Method Name: substring
Arg Types: (int, int, int, int)
Problem Statement

Problem Statement

You are given a positive integer N and a very small positive integer C. (C is at most 8.)

Let X be the following number: X = C * (10^N - 1)^2 / 81.

It can be shown that X is always a positive integer too.


We are interested in the (standard base-10) digits of X. You are given two indices A and B. Return the string formed by the A-th to B-th digit of X, inclusive.

(Digits of X are numbered from the left to the right, starting with 1.)

Constraints

  • N will be between 1 and 10^9, inclusive.
  • C will be between 1 and 8, inclusive.
  • A will be between 1 and the number of digits in X, inclusive.
  • B will be between A and the number of digits in X, inclusive.
  • (B-A) will not exceed 2,500.
Examples
0)
3
1
1
5
Returns: "12321"

For N=3 and C=1 we have X=12321. The request is to print the digits of X starting with the first (A=1) and ending with the fifth (B=5), so we print the whole number.

1)
3
1
2
5
Returns: "2321"

Same number as Example 0, but now we only return digits at positions 2-5.

2)
3
1
1
4
Returns: "1232"

Same number as Example 0, but now we only return digits at positions 1-4.

3)
100
2
7
7
Returns: "5"

For N=100 and C=2 the 7-th most significant digit of X is 5.

4)
10
1
9
12
Returns: "0098"

Note that sometimes the digit in position A can be a zero, so the string you return may have one or more leading zeros.

5)
5
6
2
7
Returns: "407259"

The full X is 740,725,926. We return its second to seventh digit.

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

Coding Area

Language: C++17 · define a public class SpecialSquare with a public method string substring(int N, int C, int A, int B) · 240 test cases · 2 s / 256 MB per case

Submitting as anonymous