Exploding CPU
Time limit1sMemory limit128 MB
Count integers in a range that factor as p1*p2*...*pn (n>=3) where consecutive primes follow p_i = A*p_{i-1}+B, starting from p_0=1.
- Level
Hard8 of 10
- Topics
- Number theory, Brute force, Math, Implementation
- Solved
- No attempts yet
Problem
A hardware company is preparing a high-performance CPU specialized for number theory. Among its instructions is PFACT, which takes a single argument and returns all of that number's prime factors at remarkable speed.
There is, however, a serious flaw: for certain special inputs the PFACT instruction malfunctions and makes the whole processor "explode". Investigation revealed that every number that triggers an explosion shares the same number-theoretic structure.
An explosive number is a number such that:
- all are distinct prime numbers;
- ;
- for every , where and are integers;
- (that is, there are at least three prime factors ).
The integers and may differ from one explosive number to another.
For example, is explosive: taking and gives , , and , and , , are all prime.
Write a program that counts how many explosive numbers lie within a given range of integers.
Input
The first line contains the number of test cases ().
Each of the following test cases is given on one line as two integers and separated by a single space ().
Output
For each test case, print on its own line the number of explosive numbers with .