ABA12D - Sum of divisors!
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
Atul Pramanik:
2013-03-15 17:40:01
I can not guess the logic. please help me..More than 10 times submitted but only WA.please share the idea please any kind man send me a mail.. My email s.atulpstu@gmail.com |
|
Atul Pramanik:
2013-03-15 12:11:42
give anyone email address I will show my code. Unexpected output, You can't believe..
|
|
Atul Pramanik:
2013-03-15 11:33:35
Why WA . Please help me .
|
|
Ouditchya Sinha:
2013-01-31 13:15:19
Nice logic, good question... |
|
Ravish Khatri:
2012-11-05 17:28:14
output for 1 1000?? |
|
Ashok:
2012-10-15 03:50:38
OEIS rocks :P
|
|
theChosenOne:
2012-09-07 14:20:56
Answer for 1 1000000 is 1000 |
|
!@#$ :
2012-08-13 11:08:35
really an out of box question.
|
|
tantu92:
2012-07-28 15:38:41
really amazing prob...!!! |
|
rock:
2012-07-28 11:22:11
output for 1 1000000?? |
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 |