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
pythondef sieve(n): sieve = [True] * (n + 1) sieve[0] = sieve[1] = False for i in range(2, int(n ** 0.5) + 1): if sieve[i]: sieve[i*i : n+1 : i] = [False] * len(sieve[i*i : n+1 : i]) primes = [i for i, is_p in enumerate(sieve) if is_p] return primes primes = sieve(10**5) T = int(input()) for _ in range(T): x, y = map(int, input().split()) if x > y: x, y = y, x n = y - x + 1 is_square_free = [True] * n max_p = int(y ** 0.5) primes_needed = [p for p in primes if p <= max_p] for p in primes_needed: p_sq = p * p if p_sq > y: continue remainder = x % p_sq start = x if remainder == 0 else x + (p_sq - remainder) if start > y: continue for k in range(start, y + 1, p_sq): is_square_free[k - x] = False 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.