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): sieve = [True] * (n + 1) sieve[0] = sieve[1] = False for i in range(2, int(math.isqrt(n)) + 1): if sieve[i]: sieve[i*i : n+1 : i] = [False] * len(sieve[i*i : n+1 : i]) primes = [i for i, is_prime in enumerate(sieve) if is_prime] return primes # Precompute primes up to sqrt(1e9) which is approximately 31623 max_prime = int(math.isqrt(10**9)) primes = sieve(max_prime) squares = [p * p for p in primes] T = int(input()) for _ in range(T): X, Y = map(int, input().split()) x, y = sorted((X, Y)) n = y - x + 1 is_square_free = [True] * n for s in squares: if s > y: break start = ((x + s - 1) // s) * s if start > y: continue # Mark all multiples of s in the range [x, y] for k in range(start, y + 1, s): idx = k - x is_square_free[idx] = 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.