ABA12D - Sum of divisors!

no tags 

Note: If you really want to learn something by solving this problem, don't hard code! There is a nice logic behind this!

---

Kartheeswaran was recently reading an article on perfect numbers, whose sum of divisors equals twice the number. He was intrigued by them and decided to generate them but to his disappointment they turned out to be quite rare. So he decided to look out for a different property related to sum of divisors. What is more interesting than a number being a prime? So he decided to look out for numbers whose sum of divisors is a prime number and he was the inventor of these special numbers he gave them the name K-numbers.

Given a range [A, B] you are expected to find the number of K-numbers in this range.

Input

The first line of input indicates the number of test cases T. Then in the following T lines there will be a pair of integers A and B.

Output

Output T lines each containing a single integer ‘c’ which denotes the number of K-numbers which lie in the interval [A, B] inclusive of the end points.

Constraints

1 <= T <= 10000

1<=A<=B<=10^6

Example

Input:
2
1 5
9 10

Output:
2
1

Explanation of Sample

1) In the range [1, 5] the K-numbers are 2 and 4 because divisors of 2 are 1 and 2 which sum up to 3, which is a prime. Divisors of 4 are 1, 2 and 4 which sum up to 7, which is a prime.

2) The only K-number in the range [9, 10] is 9.


hide comments
Diksha Jaiswal: 2014-10-23 11:42:09

Can somebody plz tell the logic...:(

Alexandre Henrique Afonso Campos: 2014-02-20 01:13:00

I have 2 AC programs with different output to these cases in particular

2
489030 597529
70813 279841

One of the AC solution gives 4 for both cases and the other gives 5.

P_Quantum: 2014-01-13 20:48:40

Nice prblm :)

Martijn Muijsers: 2013-12-08 16:15:48

I tried it legit, got correct solution but TLE fastest way I can think of :(

divij: 2013-10-25 07:27:38

any hint for logic???

Dragan Markoviæ: 2013-09-21 02:36:13

Solved it the legit way (0.20 total time. Sooo freaking satisfying.

auror: 2013-08-21 11:06:11

Are 16,25,49,64 K-Numbers??

Hitman: 2013-08-01 17:01:29

@theChosenOne pls review your answer
Answer for 1 1000000 is 37

Vaibhav Agarwal: 2013-06-08 18:50:39

@Ravish the output for 1 1000 is 8.

yaswanth: 2013-05-30 18:45:47

is there really a logic? I did this by OEIS and I didn't find any exact logic. Can anybody give me a hint of it?


Added by:Kashyap Krishnakumar
Date:2012-01-13
Time limit:0.103s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM32-GCC ASM64 MAWK BC C-CLANG NCSHARP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET
Resource:Own problem