Curiosity
Time limit1sMemory limit128 MB
For each query [a, b], find the primes in the range in order and compute an alternating sum that triples odd-indexed primes.
- Level
Medium5 of 10
- Topics
- Number theory, Prefix sum, Math, Brute force
- Solved
- No attempts yet
Problem
Namgyu is a curious person. He built a function that takes two integers and and computes a value from the primes that lie between them.
Let the primes inside the closed interval , listed from smallest to largest, be . The function multiplies every odd numbered prime by 3 and adds it, then subtracts every even numbered prime as it is.
The count decides the sign of the last term. If is odd the sum ends with , and if is even it ends with .
For example, consider . The primes from 3 to 7 inclusive are 3, 5, and 7, so the value is .
If the interval holds no prime at all, is 0.
Input
The first line contains the number of questions . ()
Each of the next lines holds one question as two integers and separated by a space. ()
Output
For each question, print the value of on its own line, in the order the questions are given.