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 precompute_mu(max_k): spf = list(range(max_k + 1)) for i in range(2, int(math.isqrt(max_k)) + 1): if spf[i] == i: for j in range(i * i, max_k + 1, i): if spf[j] == j: spf[j] = i mu = [1] * (max_k + 1) for k in range(2, max_k + 1): n = k factors = set() has_square = False temp = n while temp != 1: p = spf[temp] cnt = 0 while temp % p == 0: temp = temp // p cnt += 1 if cnt >= 2: has_square = True break factors.add(p) if has_square: mu[k] = 0 else: mu[k] = (-1) ** len(factors) return mu max_k = 31622 mu = precompute_mu(max_k) def count_square_free(n): if n == 0: return 0 res = 0 max_m = int(math.isqrt(n)) for k in range(1, max_m + 1): if mu[k] == 0: continue res += mu[k] * (n // (k * k)) return res T = int(input()) for _ in range(T): x, y = map(int, input().split()) if x > y: x, y = y, x ans = count_square_free(y) - count_square_free(x - 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.