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 max_sieve = 31622 # sqrt(1e9) is approximately 31622.7766 # Precompute smallest prime factors (SPF) for sieve spf = list(range(max_sieve + 1)) for i in range(2, int(math.isqrt(max_sieve)) + 1): if spf[i] == i: # i is a prime for j in range(i*i, max_sieve + 1, i): if spf[j] == j: spf[j] = i # Compute Mobius function for numbers up to max_sieve mobius = [0] * (max_sieve + 1) mobius[1] = 1 for k in range(2, max_sieve + 1): x = k factors = {} is_square_free = True while x != 1: p = spf[x] if p in factors: is_square_free = False break factors[p] = 1 x = x // p if is_square_free: mobius[k] = (-1) ** len(factors) else: mobius[k] = 0 def compute_count(n): if n < 0: return 0 res = 0 max_k = int(math.isqrt(n)) for k in range(1, max_k + 1): mu = mobius[k] if mu == 0: continue res += mu * (n // (k * k)) return res T = int(input()) for _ in range(T): X, Y = map(int, input().split()) a = min(X, Y) b = max(X, Y) ans = compute_count(b) - compute_count(a - 1) print(ans)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.