MAIN111 - Strictly not a Prime


Tim defines an integer as "Strictly not a Prime", if no subsequence (considering the integer as a string of digits) of the integer is a prime. He needs your help in finding how many such integers are present between two given integers A and B (including A and B).

Input

First line contains an integer T (1 <= T <= 100000) which denotes the total number test cases. Each test case consists of two integers A and B (1 <= A, B <= 100000) on a single line.

Output

For each test case, print the total count of integers which are "Strictly not a prime" between A and B (including A and B) as per Tim.

Example

Input:
2
3 6
7 10

Output:
2
3

hide comments
newbie: 2015-11-14 19:26:38

finally ac after 6 wa's good luck :) 0 & 1 are strictly not prime good luck :)

newbie: 2015-11-14 19:25:17

1. Swap if(a>b)
2. output for
1
1 100000
2568

pranjuldb: 2014-12-23 13:08:48

easy but nice one :)

Last edit: 2014-12-23 13:10:39
Bharath Reddy: 2014-09-25 10:44:51

A can be greater than B.
Swap A and B when A > B. Got 2 WA because of this.

DuM!3 !3rA!N a.k.a Sury^: 2014-09-06 21:35:06

cases like 169 is *not* "Strictly not prime" ryt? even then WA :/ Anyone to Help ? :(

Last edit: 2014-09-06 21:35:25
:(: 2014-09-06 05:56:59

Can someone give another example?

_maverick: 2013-08-16 21:06:24

OMG excellent problem tried it for three days,and made 50 attempts consisting of WA and TLE and finally got AC.Thanks for the problem learnt a lot from it.Check for all subsequences and use fast input and output and bitwise techniques optimizations , precompute as much as efficient you can.

Last edit: 2013-08-19 18:08:45
Dragan MarkoviƦ: 2013-08-16 20:53:04

Make sure you check for SUBSEQUENCES not SUBSTRINGS.

_maverick: 2013-08-15 16:51:47

i have several doubts in this problem 0 and 1 are neither prime nor composite so what i have to do in those cases here whether it should be counted or not.

_maverick: 2013-08-15 14:45:55

what is the answer for test case
1
1 100000

is the output 99985


Added by:amit karmakar
Date:2011-08-15
Time limit:1s-3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:own problem used in - http://www.spoj.pl/MAIN11/