아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Subprime

시간 제한2초메모리 제한1024 MB

요약
l번째부터 h번째 소수 중에서, 앞의 0을 허용하는 문자열 p를 부분 문자열로 포함하는 소수의 개수를 센다.
난이도

보통10점 중 7점

유형
수학, 정수론, 문자열, 완전 탐색
정답자
아직 제출이 없습니다

문제

There is an open math problem: Is every non-negative integer a substring of at least one prime number when expressed in base ten?

A positive integer is a prime number if it is greater than one and not a product of two smaller positive integers. Integer a is a substring of integer b if it is equal to an integer derived from b by deleting zero or more consecutive digits of the most and least significant digits of b. For example, 123 is a substring of: 123, 56123, 123789, 50182312365, 41237912123.

Given two integers l and h along with an integer p, you are to check how many primes between the lth smallest prime and the hth smallest prime (both ends are inclusive) contain a substring that equals p. We are interested in substrings that may include significant leading zeroes, and thus p may have leading zeroes. A prime shall be counted only once even if the integer p occurs more than once as its substring.

For example, consider l = 1, h = 10 and p = 9. This is a search from the 1st smallest prime (2) to the 10th smallest prime (29) for any prime containing the substring “9”. There are 2 such primes: 19 and 29.

입력

The first line of input has two integers l and h (1 ≤ l ≤ h ≤ 105). The second line has a sequence of 1 to 6 digits giving the integer p, which may be zero or have significant leading zeroes.

출력

Output the count of prime numbers in the given range that contain p as a substring.

예제3

  1. 예제 1

    입력
    1 10
    9
    
    예상 출력
    2
    
  2. 예제 2

    입력
    500 1000
    43
    
    예상 출력
    26
    
  3. 예제 3

    입력
    1 1000
    00
    
    예상 출력
    10