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

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/

hide comments
2015-11-14 19:26:38 newbie
finally ac after 6 wa's good luck :) 0 & 1 are strictly not prime good luck :)
2015-11-14 19:25:17 newbie
1. Swap if(a>b)
2. output for
1
1 100000
2568
2014-12-23 13:08:48 pranjuldb
easy but nice one :)

Last edit: 2014-12-23 13:10:39
2014-09-25 10:44:51 Bharath Reddy
A can be greater than B.
Swap A and B when A > B. Got 2 WA because of this.
2014-09-06 21:35:06 DuM!3 !3rA!N a.k.a Sury^
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?
2013-08-16 21:06:24 _maverick
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
2013-08-16 20:53:04 Dragan MarkoviƦ
Make sure you check for SUBSEQUENCES not SUBSTRINGS.
2013-08-15 16:51:47 _maverick
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.
2013-08-15 14:45:55 _maverick
what is the answer for test case
1
1 100000

is the output 99985
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.