Statistics

Problem Statement for "PrimeSubstrings"

Problem Statement

As you certainly know, a positive integer is called a prime if it has exactly two divisors: 1 and itself. The smallest few primes are 2, 3, 5, 7, 11, 13, 17, and so on.

A string of L digits is called a prime string if it does not contain any leading zeros and represents a prime number. E.g., "7", "47", and "10007" are prime strings but "047" and "42" aren't.

The L-quality of a number is computed by taking its base-10 representation as a string, looking at each (contiguous) substring of length L and counting those that are prime strings. E.g., the 2-quality of the number 470537 is 3 because its substrings "47", "53", and "37" are prime strings. (The substrings "70" and "05" are not prime strings.)

You are given the ints N and L. Construct an N-digit positive integer with the largest possible L-quality. Return a String with its base-10 representation. Any valid answer will be accepted.

Definition

Class:
PrimeSubstrings
Method:
construct
Parameters:
int, int
Returns:
String
Method signature:
String construct(int N, int L)
(be sure your method is public)

Constraints

  • N will be between 1 and 1000, inclusive.
  • L will be between 1 and 7, inclusive.
  • L will be less than or equal to N.

Examples

  1. 4

    2

    Returns: "5317"

  2. 7

    7

    Returns: "1301779"

    The returned number is a prime. Any 7-digit prime is a correct answer for this test case.

  3. 5

    4

    Returns: "13079"

  4. 1

    1

    Returns: "3"

  5. 2

    1

    Returns: "33"

  6. 3

    1

    Returns: "333"

  7. 47

    1

    Returns: "33333333333333333333333333333333333333333333333"

  8. 993

    1

    Returns: "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"

  9. 1000

    1

    Returns: "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"

  10. 2

    2

    Returns: "11"

  11. 3

    2

    Returns: "111"

  12. 4

    2

    Returns: "5317"

  13. 7

    2

    Returns: "1111111"

  14. 413

    2

    Returns: "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"

  15. 1000

    2

    Returns: "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"

  16. 3

    3

    Returns: "113"

  17. 4

    3

    Returns: "1131"

  18. 5

    3

    Returns: "11311"

  19. 7

    3

    Returns: "1131131"

  20. 111

    3

    Returns: "113113113113113113113113113113113113113113113113113113113113113113113113113113113113113113113113113113113113113"

  21. 997

    3

    Returns: "1131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131"

  22. 1000

    3

    Returns: "1131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131"

  23. 4

    4

    Returns: "1193"

  24. 6

    4

    Returns: "119311"

  25. 7

    4

    Returns: "1193119"

  26. 10

    4

    Returns: "1193119311"

  27. 444

    4

    Returns: "119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193"

  28. 1000

    4

    Returns: "1193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193119311931193"

  29. 5

    5

    Returns: "11939"

  30. 6

    5

    Returns: "119391"

  31. 7

    5

    Returns: "1193911"

  32. 13

    5

    Returns: "1193911939119"

  33. 1000

    5

    Returns: "1193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939119391193911939"

  34. 6

    6

    Returns: "193939"

  35. 7

    6

    Returns: "1939391"

  36. 8

    6

    Returns: "19393919"

  37. 12

    6

    Returns: "193939193939"

  38. 667

    6

    Returns: "1939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391"

  39. 1000

    6

    Returns: "1939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939391939"

  40. 7

    7

    Returns: "1301779"

  41. 8

    7

    Returns: "13339913"

  42. 9

    7

    Returns: "133399131"

  43. 10

    7

    Returns: "1333991313"

  44. 11

    7

    Returns: "13339913133"

  45. 12

    7

    Returns: "133399131333"

  46. 13

    7

    Returns: "1333991313339"

  47. 14

    7

    Returns: "13339913133399"

  48. 15

    7

    Returns: "133399131333991"

  49. 16

    7

    Returns: "1333991313339913"

  50. 312

    7

    Returns: "133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913"

  51. 644

    7

    Returns: "13339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333"

  52. 999

    7

    Returns: "133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991"

  53. 1000

    7

    Returns: "1333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913"

  54. 997

    7

    Returns: "1333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339"

  55. 55

    5

    Returns: "1193911939119391193911939119391193911939119391193911939"

  56. 200

    7

    Returns: "13339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913"

  57. 100

    7

    Returns: "1333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333"

  58. 100

    3

    Returns: "1131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131131"

  59. 986

    7

    Returns: "13339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313"

  60. 999

    6

    Returns: "193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193"

  61. 978

    7

    Returns: "133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313339913133399131333991313"

  62. 123

    6

    Returns: "193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193939193"

  63. 100

    1

    Returns: "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: