This page is still under construction.

Parts of this page are still being built. What you see may change.

Wonowon Numbers

Time limit1sMemory limit256 MB

Summary
Count primes p up to n, except 2 and 5, whose smallest alternating one-zero multiple starting and ending with 1 has exactly p minus 2 digits.
Level

Medium5 of 10

Topics
Number theory, Math
Solved
No attempts yet

Problem

A small village in northern Canada is named Wonowon, because it sits at Mile 101 of the Alaska Highway. A travelling mathematician passed through the village and named a family of numbers after it. A wonowon number is a positive integer whose decimal representation starts with 1, ends with 1, and alternates between 1 and 0. The four smallest wonowon numbers are 101, 10101, 1010101 and 101010101, so a wonowon number always has an odd number of digits, at least three.

No wonowon number is divisible by 2 or by 5. Every other prime is conjectured to divide some wonowon number. For example, 3 divides 10101 (3×33673 \times 3367), 7 divides 10101 (7×14437 \times 1443), and 11 divides 101010101010101010101 (11×918273645546372819111 \times 9182736455463728191).

Assume the conjecture holds, and let W(p)W(p) be the number of digits of the smallest wonowon number divisible by the prime pp. Then W(3)=5W(3) = 5, W(7)=5W(7) = 5, W(11)=21W(11) = 21, W(13)=5W(13) = 5, W(17)=15W(17) = 15 and W(19)=17W(19) = 17.

Experiments show that W(p)=p−2W(p) = p - 2 holds for many primes, among them 7, 17 and 19. Given an integer nn, count the primes pp with p≤np \le n, p≠2p \ne 2, p≠5p \ne 5 and W(p)=p−2W(p) = p - 2.

Input

The first and only line contains one integer nn. (3≤n≤100003 \le n \le 10000)

Output

Print, on one line, the number of primes pp with p≤np \le n, p≠2p \ne 2, p≠5p \ne 5 and W(p)=p−2W(p) = p - 2.

Examples2

  1. Example 1

    Input
    20
    
    Expected output
    3
    
  2. Example 2

    Input
    100
    
    Expected output
    14