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 # Precompute the Möbius function up to sqrt(1e9) max_d = int(math.isqrt(10**9)) + 1 mu = [1] * (max_d + 1) is_prime = [True] * (max_d + 1) is_prime[0] = is_prime[1] = False for p in range(2, max_d + 1): if is_prime[p]: # Mark multiples of p for mu for m in range(p, max_d + 1, p): mu[m] *= -1 # Mark multiples of p² for mu p_square = p * p for m in range(p_square, max_d + 1, p_square): mu[m] = 0 # Sieve multiples of p starting from p² for m in range(p * p, max_d + 1, p): is_prime[m] = False def count_square_free(x): if x == 0: return 0 res = 0 max_d_x = int(math.isqrt(x)) for d in range(1, max_d_x + 1): res += mu[d] * (x // (d * d)) return res T = int(input()) for _ in range(T): X, Y = map(int, input().split()) a = min(X, Y) b = max(X, Y) cnt_a_minus_1 = count_square_free(a - 1) if a > 0 else 0 cnt_b = count_square_free(b) print(cnt_b - cnt_a_minus_1)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.