Game of numbers is a game where you are given two integers (X and Y), and you have to…
- User
Game of numbers is a game where you are given two integers (X and Y), and you have to print the number of special numbers between X and Y both inclusive.
The property of a special numbers is as follows:
A special number is not divisible by any number of the form ZZ* where (Z; >; 1). Input: T, the number of test cases. Each test case consists of two space separated integers denoting X and Y.Output: The required answer in one line for each test case.
Constraints:
1 ≤ T ≤ 10
1 ≤ X,Y ≤ 10 ^ 9 0 ≤ |X-Y| ≤ 10^6SAMPLE INPUT 1 1 10
SAMPLE OUTPUT 7
Explanation
In given test case, 4,8 and 9 are not special.
Assistant
pythonimport math def sieve(n): is_prime = [True] * (n + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(math.sqrt(n)) + 1): if is_prime[i]: for j in range(i * i, n + 1, i): is_prime[j] = False primes = [i for i, val in enumerate(is_prime) if val] return primes primes = sieve(31622) T = int(input()) for _ in range(T): X, Y = map(int, input().split()) a = min(X, Y) b = max(X, Y) size = b - a + 1 is_square_free = [True] * size for p in primes: s = p * p if s > b: break first = ((a + s - 1) // s) * s if first > b: continue num = (b - first) // s + 1 start_idx = first - a end_slice = start_idx + s * num is_square_free[start_idx:end_slice:s] = [False] * num print(sum(is_square_free))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.