VECTAR8 - Primal Fear

no tags 

Changu and Mangu are afraid of prime numbers, but they are not afraid of all prime numbers. They were afraid of only a special kind of prime numbers. They are afraid of the prime numbers (without the digit zero, they love all the primes which have digits 0 in them) that remain prime no matter how many of the leading digits are omitted. For example, they are afraid of 4632647 because it doesn't have the digit 0 and each of its truncations (632647, 32647, 2647, 647, 47, and 7) are primes.

You are given a simple task, given a number of N, find out the number of primes not greater that N, that changu and mangu are afraid of.

Input

The first line contains T, the number of test cases. T lines follow, each containing a number N.

Output

On each line print the number of primes not greater that N, that changu and mangu are afraid of.

Example

Input:
3
2
3
4

Output:
1
2
2

Constraints

T ≤ 10^5

1 ≤ N < 10^6


hide comments
ks1999: 2018-04-20 17:09:25

My 200th on SPOJ.
Enjoyed solving it.

m2do: 2018-03-15 21:27:29

1 is considered non-prime. caused me 4 WAs. finally AC :)

atikahamedutso: 2018-01-28 17:26:50

easy one ac in one go :D
sieve
and precomputing

itachi_2016: 2018-01-04 18:49:02

Awesome question @Piyush. Can you look into my code and suggest some improvements if possible. ID : 20920855.

geet313: 2017-12-17 10:01:53

Sieve works here ?

Last edit: 2017-12-17 10:03:36
omarwageeh: 2017-09-11 09:58:19

make sure you check that all the truncations of a prime that has no zeroes are prime as in the example.... 632647, 32647, 2647, 647, 47, and 7
Caused me 3 WA

nihal_magdy: 2017-08-18 11:48:23

@piyush can you see what is the wrong test i get with my code 19995055

rohit659: 2017-04-06 21:42:37

NICE PROBLEM !!!
AC IN ONE GO!!!

dwij28: 2016-10-07 23:40:01

A very nice problem. In fact all problems by @Piyush Kumar i.e the VECTAR series are very nice. :)

rainy jain : 2016-09-13 02:32:57


Last edit: 2016-09-13 09:21:17

Added by:Piyush Kumar
Date:2016-07-04
Time limit:0.300s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY