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
coder_hsnake:
2017-02-01 15:08:57
can take help from
|
|
piyushmittal:
2017-02-01 09:10:39
very good question...
|
|
madhavgaba:
2017-01-19 11:06:29
perhaps the logic is that there exist only 37 such integers in 1 and 10^6............only hard code gave AC:( Last edit: 2017-01-19 11:07:01 |
|
uselesscoder:
2016-07-30 12:45:57
Pretty easy logic got Accepted in 0.00 sec , now that's a wonder for me
|
|
sanjay:
2016-05-29 09:28:40
USED OEIS GOT AC.NOW THINKING WHAT WOULD BE LOGIC.HOPE I WILL GET IT :) |
|
praval_singhal:
2016-05-05 09:35:58
Solved it with the help of OEIS. please share the logic with me if you want, mail me at no.sharing@cheating.com
|
|
sumit_saurav:
2016-04-24 15:37:29
i have applied logic that every square of an integer will fullfill this value ,if there is any other case possible please tell me.
|
|
i_love_coding:
2016-02-29 13:43:53
Good but not the best logic..one can easily find it out by designing more test cases..:) |
|
koniko:
2016-02-18 20:32:27
easy logic #teehee |
|
r_ash:
2016-01-21 18:58:26
I got the trick woo..hoo..
|
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 |