PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000174. Nỗi sợ nguyên tố (Primal Fear)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Nỗi sợ nguyên tố (Primal Fear)

Primal Fear

Phuoc Hung OJ ID: PRIME000179
Original source: SPOJ VECTAR8

Problem statement

Count primes p≤Np\le N with no zero digit, such that repeatedly removing the leftmost digit always leaves a prime. A one-digit prime qualifies.

Input

One integer NN.

Output

Print the count of qualifying primes not greater than NN.

Subtasks

  • Subtask 1 (20 points): 1≤N≤1 0001\le N\le 1\,000.
  • Subtask 2 (30 points): 1 001≤N≤100 0001\,001\le N\le 100\,000.
  • Subtask 3 (50 points): 100 001≤N≤999 999100\,001\le N\le 999\,999.

Example

Input

2

Output

1

Explanation: Only 22 is prime in the range and satisfies all conditions.