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
pythonmax_k = 10**5 spf = list(range(max_k + 1)) for i in range(2, int(max_k**0.5) + 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): x = k factors = {} flag = False while x != 1: p = spf[x] if p in factors: factors[p] += 1 if factors[p] >= 2: flag = True break else: factors[p] = 1 x = x // p if flag: mu[k] = 0 else: mu[k] = (-1) ** len(factors) def count_square_free(n): if n == 0: return 0 res = 0 max_k = int(n**0.5) for k in range(1, max_k + 1): if mu[k] == 0: continue res += mu[k] * (n // (k * k)) return res import sys input = sys.stdin.read().split() T = int(input[0]) idx = 1 for _ in range(T): X = int(input[idx]) Y = int(input[idx + 1]) idx += 2 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.