description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$. Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$). -----Output----- For each test case, print one integer β€” the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. -----Examples----- Input 3 3 6 9 Output 0 1 1 -----Note----- The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$.
t = int(input()) for i in range(t): n = int(input()) c = 0 f = int((2 * n - 1) ** 0.5) g = 3 while g <= f: if g % 2 == 1: c += 1 g += 1 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$. Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$). -----Output----- For each test case, print one integer β€” the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. -----Examples----- Input 3 3 6 9 Output 0 1 1 -----Note----- The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$.
def solve(): n = int(input()) l, r = 0, int(1000000000.0) while r - l > 1: m = (r + l) // 2 if m * m <= (n - 1) * 2 + 1: l = m else: r = m print((l - 1) // 2) return ans = 0 for a in range(3, 64000, 2): qa = a * a if qa & 1 == 0: continue b = (qa - 1) // 2 c = b + 1 if c > n: break if c * c == b * b + qa: ans += 1 print(ans) t = int(input()) while t > 0: t -= 1 solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$. Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $c = a^2 - b$. Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $(3, 4, 5)$: $5 = 3^2 - 4$, so, according to Vasya's formula, it is a Pythagorean triple. When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of one line containing one integer $n$ ($1 \le n \le 10^9$). -----Output----- For each test case, print one integer β€” the number of triples of integers $(a, b, c)$ with $1 \le a \le b \le c \le n$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with. -----Examples----- Input 3 3 6 9 Output 0 1 1 -----Note----- The only Pythagorean triple satisfying $c = a^2 - b$ with $1 \le a \le b \le c \le 9$ is $(3, 4, 5)$; that's why the answer for $n = 3$ is $0$, and the answer for $n = 6$ (and for $n = 9$) is $1$.
def check(num): if (num**2 + 1) // 2 <= n: return True return False for nt in range(int(input())): n = int(input()) low = 1 high = n while low < high: mid = (low + high) // 2 if not mid % 2: mid += 1 if check(mid): low = mid + 1 else: high = mid - 1 if not low % 2: if check(low + 1): print(low // 2) else: print(low // 2 - 1) elif check(low): print(low // 2) else: print(low // 2 - 1)
FUNC_DEF IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): lo, hi = 0, n * 5 ans = lo while lo <= hi: mid = lo + (hi - lo) // 2 if self.findTrailingZeros(mid) >= n: ans = mid hi = mid - 1 else: lo = mid + 1 return ans def findTrailingZeros(self, x): mul = 5 zeroes = 0 while x >= mul: zeroes += x // mul mul *= 5 return zeroes
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def zeros(self, num): count = 0 while num: num //= 5 count += num return count def findNum(self, n: int): if n == 0: return 0 l, r = 5, 5 * n while l < r: mid = (l + r) // 2 if self.zeros(mid) >= n: r = mid else: l = mid + 1 return l
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def count(self, n): ans = 0 ch = 5 while n >= ch: ans += n // ch ch *= 5 return ans def findNum(self, n: int): l = 1 while self.count(l) < n: l *= 5 l, r = l // 5, l res = r while l <= r: m = (l + r) // 2 if self.count(m) >= n: res = m r = m - 1 else: l = m + 1 return res
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def cfive(self, m): c = 0 while m: c += m // 5 m = m // 5 return c def findNum(self, n: int): s = 1 e = 5 * n while s <= e: m = (s + e) // 2 nfive = self.cfive(m) if nfive >= n: ans = m e = m - 1 if nfive < n: s = m + 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): d = 0 i = 1 while d < n: k = 5 * i while k % 5 == 0: d += 1 k = k / 5 i += 1 return (i - 1) * 5
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP NUMBER VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): l = 1 r = int(100000.0) ans = -1 def zero(x): count = 0 while x > 0: count += x // 5 x = x // 5 return count while l <= r: mid = (l + r) // 2 val = zero(mid) if val >= n: ans = mid r = mid - 1 else: l = mid + 1 return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def poss(p, n): temp = p count = 0 f = 5 while f <= temp: count += temp // f f = f * 5 return count >= n if n == 1: return 5 low = 0 high = 5 * n while low < high: mid = low + high >> 1 if poss(mid, n): high = mid else: low = mid + 1 return low
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): k = 1 count = 0 while count < n: k += 1 x = k while x % 5 == 0: count += 1 x //= 5 return k
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): fact = 24 s = 5 zeros = 10 while n > 0: fact = fact * s temp = s count = 0 while temp >= 5: temp //= 5 count += temp if count >= n: return s s += 5 return s - 1
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR IF VAR VAR RETURN VAR VAR NUMBER RETURN BIN_OP VAR NUMBER
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def trailingzeros(self, n): c = 0 while n: n //= 5 c += n return c def binarysearch(self, l, r, k): if l <= r: mid = (l + r) // 2 t = self.trailingzeros(mid) if t >= k: return self.binarysearch(l, mid - 1, k) else: return self.binarysearch(mid + 1, r, k) return l def findNum(self, n: int): return self.binarysearch(0, 5 * n, n)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF VAR RETURN FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): if n == 1: return 5 def check(m, n): res = 0 while m >= 5: m = m // 5 res += m return res < n l = 0 u = 5 * n while l < u: m = (l + u) // 2 if check(m, n): l = m + 1 else: u = m return l
CLASS_DEF FUNC_DEF VAR IF VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
def f(x: int): xx = x ans = 0 while xx: ans += xx // 5 xx //= 5 return ans def f_inverse(n): l = 0 r = 10**9 while l < r: mid = (l + r) // 2 if f(mid) >= n: r = mid else: l = mid + 1 return l class Solution: def findNum(self, n: int): return f_inverse(n)
FUNC_DEF VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
def count_trails(n): count = 0 f = 5 while f <= n: count += n // f f = f * 5 return count class Solution: def findNum(self, n: int): s, e = 0, 5 * n while s <= e: mid = s + (e - s) // 2 if count_trails(mid) >= n: e = mid - 1 else: s = mid + 1 return s
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): low = 0 high = 5 * n while low <= high: mid = (low + high) // 2 count = 0 i = 5 while i <= mid: count += mid // i i *= 5 if count >= n: high = mid - 1 else: low = mid + 1 return low
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def count(self, a): c = 0 while a: a = a // 5 c += a return c def findNum(self, n: int): i = 1 e = 5 * n ans = 1 while i <= e: mid = (i + e) // 2 if self.count(mid) >= n: ans = mid e = mid - 1 else: i = mid + 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def check(t, n): ans = 0 while t: ans += t // 5 t = t // 5 if ans >= n: return 1 else: return 0 high = n low = 1 while low <= high: mid = (low + high) // 2 if check(mid * 5, n): high = mid - 1 else: low = mid + 1 return low * 5
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def ispossible(num, n): cnt = 0 while num >= 5: cnt += num // 5 num = num // 5 if cnt >= n: return True return False if n == 1: return 5 elif n == 0: return 0 start = 6 end = n * 5 ans = 0 while start <= end: mid = start + end >> 1 if ispossible(mid, n): ans = mid end = mid - 1 else: start = mid + 1 return ans
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): lo = 0 hi = 10**6 ans = -1 while lo <= hi: mi = (lo + hi) // 2 if self.getZeroes(mi) >= n: ans = mi hi = mi - 1 else: lo = mi + 1 return ans def getZeroes(self, x): sm = 0 while x // 5: sm += x // 5 x = x // 5 return sm
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def trail(ni): a = 0 if ni > 4: while True: ni = ni // 5 a = a + ni if ni < 5: break return a l = 1 h = 5 * 10**4 while l <= h: mid = l + h >> 1 if trail(mid) >= n: h = mid - 1 else: l = mid + 1 return l
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): count = 0 for i in range(5, 100000, 5): num = i while num % 5 == 0: num = num / 5 count += 1 if count == n: return i
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def isok(num): n_zeros = 0 j = num d = 5 while j >= d: n_zeros += j // d d *= 5 return n_zeros low = 0 high = 5 * n res = 0 while low <= high: mid = (low + high) // 2 if isok(mid) >= n: res = mid high = mid - 1 else: low = mid + 1 return res
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def countZero(p, n): fives = 5 count = 0 val = p while fives <= val: count += val // fives fives *= 5 return count >= n def findNum(self, n: int): low = 0 high = 5 * n if n == 1: return 5 while low < high: mid = low + high >> 1 if Solution.countZero(mid, n): high = mid else: low = mid + 1 return low
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
def zerocheck(a, n): zeroes = 0 num = 1 while num <= a: num = num * 5 zeroes += a // num return zeroes >= n class Solution: def findNum(self, n: int): if n == 1: return 5 low = 5 high = 5 * n while low != high: mid = (low + high) // 2 if zerocheck(mid, n): high = mid else: low = mid + 1 return low
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR VAR CLASS_DEF FUNC_DEF VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def numOfZeros(num): c = 0 while num >= 5: num //= 5 c += num return c l, h = 1, 1000000000 while l < h: mid = l + (h - l) // 2 if numOfZeros(mid) < n: l = mid + 1 else: h = mid return l
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): if n < 6: return 5 * n k = 1 ans = 0 limit_k = 1 cumsum = [1] while limit_k < n: limit_k += 5**k cumsum.append(limit_k) k += 1 ans = 5**k k -= 1 l = cumsum[k - 1] limit_k -= 1 while True: if limit_k - k + 1 <= n <= limit_k + 1: return ans else: limit_k -= l ans -= 5**k if limit_k < n: limit_k += l ans += 5**k limit_k -= 1 k -= 1 l = cumsum[k - 1]
CLASS_DEF FUNC_DEF VAR IF VAR NUMBER RETURN BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER WHILE VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): count = 0 num = 5 while True: temp = num while temp % 5 == 0: count += 1 temp //= 5 if count >= n: return num num += 5
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR VAR NUMBER
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): if n == 1: return 5 low = 0 high = 5 * n while low < high: mid = int((low + high) / 2) if ob.check(mid, n): high = mid else: low = mid + 1 return low def check(self, p: int, n: int): temp = p count = 0 f = 5 while f <= temp: count += temp // f f *= 5 return count >= n
CLASS_DEF FUNC_DEF VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def zero_count(n): temp = n count = 0 f = 5 while f <= temp: count += temp // f f = f * 5 return count left = 0 right = n * 5 ans = right while left <= right: mid = (left + right) // 2 current = zero_count(mid) if current < n: left = mid + 1 else: ans = min(ans, mid) right = mid - 1 return ans
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def check(p, n): temp = p f = 5 count = 0 while f <= p: count += temp // f f *= 5 if count >= n: return True else: return False low = 0 high = n * 5 ans = 0 while low <= high: mid = (low + high) // 2 res = check(mid, n) if res == True: ans = mid high = mid - 1 else: low = mid + 1 return ans
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def fives(n): count = 0 while n: if n % 5 != 0: break n = n // 5 count += 1 return count x = 0 factorial = 0 while x < n: factorial += 5 x += fives(factorial) return factorial
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR RETURN VAR
Given a number n. The task is to find the smallest number whose factorial contains at least n trailing zeroes. Example 1: Input: n = 1 Output: 5 Explanation : 5! = 120 which has at least 1 trailing 0. Example 2: Input: n = 6 Output: 25 Explanation : 25! has at least 6 trailing 0. User Task: Complete the function findNum() which takes an integer N as input parameters, and returns the answer. Expected Time Complexity: O(log_{2} N * log_{5} N). Expected Auxiliary Space: O(1). Constraints: 1 <= n <= 10^{4}
class Solution: def findNum(self, n: int): def make(x): t = 0 k = 5 m = 1 while x // k > 0: t += x // k m *= 2 k *= 5 if t >= n: return True return False x, y = 0, 2**32 while x <= y: m = x + (y - x) // 2 if not make(m): x = m + 1 else: y = m - 1 return x
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
def close(n): for i in range(31): if n == arr[i]: return arr[i], arr[i] if n > arr[i] and n < arr[i + 1]: return arr[i], arr[i + 1] def calx(n, min): a, b = close(n) if a == b and b == min: return b / 2 if a == b: return a if b == min: return a if a == min: return a / 2 if b - n >= n - a: return a if a != min else a / 2 if b - n < n - a: return b if b != min else b / 2 arr = [] for i in range(31): arr.append(2**i) t = int(input()) for i in range(t): num = int(input()) min, max = close(num) if num == 1: print("2") elif min == max: print("1") else: maxd = max + 1 - num mind = abs(min + calx(num - min, min) - num) diff = maxd if maxd < mind else mind print(diff)
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR RETURN VAR VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR RETURN VAR IF VAR VAR RETURN BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
var = [] for i in range(0, 32): for j in range(i + 1, 32): var.append(2**i + 2**j) var.sort() for i in range(int(input())): n = int(input()) j = 0 while True: if var[j] >= n: break j += 1 print(min(abs(var[j] - n), abs(var[j - 1] - n)))
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
t = int(input()) arr = [] for i in range(1, 33): for j in range(i): arr.append((1 << i) + (1 << j)) arr.sort() def ans(n): low, high = 0, len(arr) res, diff = float("inf"), float("inf") while low <= high: mid = (low + high) // 2 currdiff = abs(n - arr[mid]) if currdiff < diff: diff = currdiff res = mid if arr[mid] == n: return n if arr[mid] > n: high = mid - 1 else: low = mid + 1 return arr[res] for _ in range(t): n = int(input()) print(abs(n - ans(n)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
l = [] for i in range(31): for j in range(i + 1, 31): l.append(2**i + 2**j) l.sort() def getClosest(val1, val2, target): if target - val1 >= val2 - target: return val2 else: return val1 def findClosest(l1, target): i = 0 j = l1 mid = 0 while i < j: mid = (i + j) // 2 if l[mid] == target: return l[mid] if target < l[mid]: if mid > 0 and target > l[mid - 1]: return getClosest(l[mid - 1], l[mid], target) j = mid else: if mid < n - 1 and target < l[mid + 1]: return getClosest(l[mid], l[mid + 1], target) i = mid + 1 return arr[mid] for t in range(int(input())): n = int(input()) l1 = len(l) ans = 0 if n <= 3: print(3 - n) else: print(abs(findClosest(l1, n) - n))
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
n = int(input()) queries = [int(input()) for i in range(n)] def binary_search(A, value): if len(A) == 0: return 0 mid = len(A) // 2 if A[mid] == value: return mid elif value < A[mid]: return binary_search(A[:mid], value) else: return mid + 1 + binary_search(A[mid + 1 :], value) A = [] for i in range(0, 40): for j in range(i + 1, 40): A.append(2**i + 2**j) A = sorted(A) for query in queries: value = query index = binary_search(A, value) print(min([abs(A[i] - value) for i in range(max(0, index - 5), index + 5)]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
lst = [] for i in range(32): for j in range(32): if i != j: lst.append(2**i + 2**j) lst.sort() def bin_search(x, low, high): if low > high: return min(abs(x - lst[low]), abs(x - lst[low - 1]), abs(x - lst[low + 1])) else: mid = low + (high - low) // 2 if x == lst[mid]: return 0 elif x < lst[mid]: return bin_search(x, low, mid - 1) else: return bin_search(x, mid + 1, high) d = {} T = int(input()) for k in range(T): N = int(input()) a = bin_search(N, 0, len(lst) - 1) if N not in d: print(a) d[N] = a else: print(d[N])
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
T = int(input()) lst = [] for i in range(31): for j in range(i): lst.append(2**i + 2**j) lst.sort() def bound_search(lst, x, compare): lo = 0 up = len(lst) while lo < up: mid = (lo + up) // 2 if compare(x, lst[mid]): up = mid else: lo = mid + 1 return lo upper = lambda x, elem: x < elem while T > 0: N = int(input()) nxt = bound_search(lst, N, upper) prev = bound_search(lst, N, upper) - 1 ans = min(abs(N - lst[nxt]), abs(N - lst[prev])) print(ans) T -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
def bin(arr, i, j, val): while i <= j: mid = (i + j) // 2 if arr[mid] == val or arr[mid] < val and val < arr[mid + 1]: return mid elif arr[mid] < val: i = mid + 1 elif arr[mid] > val: j = mid - 1 li = [] for i in range(31): for j in range(31): if i != j: li.append(2**i + 2**j) li.sort() for l in range(int(input())): N = int(input()) if N == 1: print(2) elif N == 2: print(1) else: i = bin(li, 0, len(li) - 1, N) print(min(N - li[i], li[i + 1] - N))
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
def bin(start, end): while start < end: mid = (start + end) // 2 if la[mid] < n: start = mid + 1 else: end = mid - 1 return min(abs(n - la[start]), abs(n - la[start + 1]), abs(n - la[start - 1])) la = [] for i in range(35): for j in range(35): if i != j: la.append(2**i + 2**j) la = sorted(list(set(la))) hash = {} t = int(input()) for _ in range(t): n = int(input()) mini = 10**18 if n not in hash: z = bin(0, len(la) - 1) print(z) hash[n] = z else: print(hash[n])
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
t = int(input()) for _ in range(t): n = int(input()) n_bin = bin(n)[2:] count = 0 i = 0 while i < len(n_bin): if n_bin[i] == "1": count += 1 if count == 2: break i += 1 if count == 1: if n == 1: print(2) else: print(1) elif count == 2 and i == len(n_bin) - 1: print(0) elif i == 1: ans_1 = pow(2, len(n_bin)) + 1 ans_2 = int("0b" + n_bin[i + 1 :], 2) print(min(ans_1 - n, ans_2)) else: ans_1 = pow(2, len(n_bin[i:])) - int("0b" + n_bin[i:], 2) ans_2 = int("0b" + n_bin[i + 1 :], 2) print(min(ans_1, ans_2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
l = [] for i in range(31): for j in range(i + 1, 31): l.append(2**i + 2**j) l1 = len(l) l.sort() for t in range(int(input())): n = int(input()) ans = 0 if n <= 3: print(3 - n) else: for i in range(l1): if l[i] >= n: ans = min(l[i] - n, n - l[i - 1]) break print(ans)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
def bs(arr, l, h, x): if h >= l: mid = (h + l) // 2 if arr[mid] == x: return 1 elif arr[mid] > x: return bs(arr, l, mid - 1, x) else: return bs(arr, mid + 1, h, x) else: return -1 def bss(arr, l, h, x): if h >= l: mid = (h + l) // 2 if arr[mid] > x: if arr[mid - 1] < x: print(min(x - arr[mid - 1], arr[mid] - x)) else: bss(arr, l, mid - 1, x) elif arr[mid] < x: if arr[mid + 1] > x: print(min(x - arr[mid], arr[mid + 1] - x)) else: bss(arr, mid + 1, h, x) a = [] for i in range(31): for j in range(31): if i != j: a.append(2**j + 2**i) a = list(set(a)) a.sort() for _ in range(int(input())): n = int(input()) m = bs(a, 0, len(a) - 1, n) if m == 1: print("0") elif m == -1 and n >= 3: p = bss(a, 0, len(a) - 1, n) else: print(3 - n)
FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
nums = [] for x in range(33): for y in range(33): if x == y: continue nums.append(2**x + 2**y) nums.sort() def binary_search(lo, hi, condition, target): while lo <= hi: mid = (lo + hi) // 2 result = condition(mid) if result == "found": if nums[mid] == target: return 0 elif nums[mid] < target < nums[mid + 1]: return min(abs(nums[mid + 1] - target), abs(nums[mid] - target)) else: return min(abs(nums[mid - 1] - target), abs(nums[mid] - target)) elif result == "left": hi = mid - 1 else: lo = mid + 1 return -1 def find_num(nums, target): def condition(mid): if ( nums[mid] == target or nums[mid] < target < nums[mid + 1] or nums[mid - 1] < target < nums[mid] ): return "found" elif nums[mid] < target: return "right" else: return "left" return binary_search(0, len(nums) - 1, condition, target) for i in range(int(input())): n = int(input()) if n == 1: print(2) elif n == 2: print(1) else: print(find_num(nums, n))
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN STRING IF VAR VAR VAR RETURN STRING RETURN STRING RETURN FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
t = int(input()) for _ in range(t): n = int(input()) s = bin(n)[2:] c = s.count("1") if n == 1: print(2) else: k = 1 while k <= n: k = k << 1 k = k >> 1 if k == n: print("1") else: n = n - k j = 1 while j <= n: j = j << 1 j = j >> 1 if j * 2 != k: print(min(abs(j * 2 - n), abs(j - n))) else: print(min(abs(j - n), abs(j * 2 + 1 - n)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
t = int(input()) x = [] for i in range(0, 31): for j in range(i + 1, 31): k = (1 << i) + (1 << j) x.append(k) x.sort() def search(n): i = int(0) while i < len(x): if x[i] > n: break i = i + 1 return i while t > 0: n = int(input()) result = search(n) m = int(0) if result == 0: m = x[0] - n elif result == len(x): m = n - x[result] else: a = x[result] - n b = n - x[result - 1] if a < b: m = a else: m = b print(m) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
def cal(num): x = 0 while pow(2, x) < num: x = x + 1 return x - 1 n = int(input()) for i in range(0, n): num = int(input()) if num == 1: print(2) elif num == 2: print(1) else: x = cal(num) num1 = num - pow(2, x) y = cal(num1) if num > pow(2, x - 1) + pow(2, x): print(min(num1 - pow(2, y), pow(2, x + 1) + 1 - num)) else: print(min(num1 - pow(2, y), pow(2, y + 1) - num1))
FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR
------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an integer $M$ that can be represented in the form $2^{x} + 2^{y}$ (where $x$ and $y$ are non-negative integers such that $x \neq y$). In order to do that, he can perform two types of operations: add $1$ to $N$ subtract $1$ from $N$ However, Sheokand is preparing for his exams. Can you help him find the minimum number of operations required to convert $N$ into a valid integer $M$? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first and only line of each testcase contains a single integer $N$. ------ Output ------ For each test case, print a single line containing one integer β€” the minimum required number of operations. ------ Constraints ------ $1 ≀ T ≀ 100,000$ $1 ≀ N ≀ 10^{9}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 1,000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 10 22 4 ----- Sample Output 1 ------ 0 2 1 ----- explanation 1 ------ Example case 1: $N=10$ is already in the form $2^{x} + 2^{y}$, with $x=3$ and $y=1$. Example case 2: $N=22$ can be converted into $M=20=2^{2}+2^{4}$ or $M=24=2^{3}+2^{4}$ in two operations. Example case 3: $N=4$ can be converted into $M=3=2^{0}+2^{1}$ or $M=5=2^{0}+2^{2}$ in one operation.
a = [1, 2] for i in range(29): a.append(a[-1] * 2) c = [] for i in range(len(a) - 1): k = a[i] for j in range(i + 1, len(a)): c.append(k + a[j]) c.sort() for i in range(int(input())): l = int(input()) if l <= 3: print(3 - l) else: for j in range(465): if c[j] >= l: print(min(c[j] - l, l - c[j - 1])) break
ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def nineDivisors(self, n): c = 0 limit = int(n**0.5) prime = [i for i in range(limit + 1)] i = 2 while i * i <= limit: if prime[i] == i: for j in range(i * i, limit + 1, i): if prime[j] == j: prime[j] = i i += 1 for i in range(2, limit + 1): p = prime[i] q = prime[i // prime[i]] if p * q == i and q != 1 and p != q: c += 1 elif prime[i] == i: if i**8 <= n: c += 1 return c
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def countdiv(self, n): limit = int(n**0.5) skip = 2 conta = 1 check = 3 if n % 2 == 0: skip = 1 conta = 2 while check < limit: if n % check == 0: conta = conta + 1 check = check + skip if conta > 4: return False if conta == 4: return True else: False def prime_factors(self, n): i = 2 while i * i <= n: if n % i: i += 1 else: return 1 return 0 def nineDivisors(self, N): conta = 0 check = False primi = [2] pos = 0 limit = int(N**0.5) for i in range(3, limit + 1): if self.prime_factors(i) == 0: while pos >= 0: if primi[pos] * i > limit: check = True pos -= 1 else: break conta = conta + pos + 1 primi.append(i) if not check: pos = len(primi) - 1 pos = 0 while primi[pos] ** 8 <= N: conta += 1 pos += 1 return conta if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER EXPR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def isprime(self, n): if n < 2: return False if n == 3 or n == 2 or n == 5: return True if n % 2 == 0 or n % 3 == 0 or n % 5 == 0: return False for i in range(5, int(n**0.5) + 1, 6): if n % (i + 2) == 0 or n % (i + 6) == 0: return False return True def nineDivisors(self, N): if N < 36: return 0 prime = [] for i in range(2, int(N**0.5) + 1): if self.isprime(i): prime.append(i) count = 0 for i in range(len(prime)): x = prime[i] if x**8 <= N: count += 1 else: break for i in range(len(prime) - 1): x = prime[i] flag = True l = i + 1 h = len(prime) - 1 while l <= h: mid = (l + h) // 2 if x * x * prime[mid] ** 2 <= N: count += mid - l + 1 l = mid + 1 flag = False else: h = mid - 1 if flag: break return count if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def nineDivisors(self, n): c = 0 limit = int(n**0.5) prime = [i for i in range(limit + 1)] i = 2 while i * i <= limit: if prime[i] == i: for j in range(i * i, limit + 1, i): if prime[j] == j: prime[j] = i i += 1 for i in range(2, limit + 1): p = prime[i] q = prime[i // prime[i]] if p * q == i and q != 1 and p != q: c += 1 elif prime[i] == i: if i**8 <= n: c += 1 return c if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def nineDivisors(self, n): res = int(n**0.5) ar = [i for i in range(res + 1)] for i in range(2, res + 1): if ar[i] == i: for j in range(i * i, res + 1, i): if ar[j] == j: ar[j] = i ans = 0 for i in range(2, res + 1): p = ar[i] q = ar[i // ar[i]] if p * q == i and p != q and q != 1: ans += 1 elif ar[i] == i and i**8 < n: ans += 1 return ans def factors(self, n): num = n * n ans = 0 i = 1 while i <= n: if num % i == 0: ans += 2 if i * i == num: ans -= 1 i += 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def nineDivisors(self, n): l = [1] * (int(n**0.5) + 1) l[0], l[1] = 0, 0 x = len(l) for i in range(2, int(x**0.5) + 1): if l[i] == 1: for j in range(i * i, x, i): l[j] = 0 c = 0 for i in range(2, x): if l[i] == 1: if (i * i) ** 2 > n: break for j in range(i, x): if l[j] == 1: if i == j: a = i * i a = a * a a = a * a if a <= n: c += 1 else: a = i * j a *= a if a <= n: c += 1 else: break return c if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def nineDivisors(self, n): res = int(n**0.5) ar = [i for i in range(res + 1)] for i in range(2, res + 1): if ar[i] == i: for j in range(i * i, res + 1, i): if ar[j] == j: ar[j] = i ans = 0 for i in range(2, res + 1): p = ar[i] q = ar[i // ar[i]] if p * q == i and p != q and q != 1: ans += 1 elif ar[i] == i and i**8 < n: ans += 1 return ans def factors(self, n): num = n * n ans = 0 i = 1 while i <= n: if num % i == 0: ans += 2 if i * i == num: ans -= 1 i += 1 return ans if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def nineDivisors(self, N): t = 0 s = int(pow(N, 0.5)) + 1 primes = [(1) for i in range(s)] arr = [] for i in range(2, s): if primes[i] and i != 1: arr.append(i) for j in range(i + i, s, i): primes[j] = 0 t = 0 for i in range(len(arr)): for j in range(i + 1, len(arr)): if arr[i] * arr[j] < s: t += 1 else: break for i in arr: if i**8 <= N: t += 1 else: break return t if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def find_prime(self, num): arr = [i for i in range(num)] for i in range(2, num): if arr[i] == i: j = i while j < num: if arr[j] == j: arr[j] = i j = j + i return arr def nineDivisors(self, N): count = 0 prime = self.find_prime(int(N**0.5 + 1)) for i in range(2, int(N**0.5) + 1): a = prime[i] b = prime[i // a] if a != b and b != 1 and a * b == i or prime[i] == i and i**8 <= N: count += 1 return count if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def nineDivisors(self, N): def SieveOfEratosthenes(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 x = [] for p in range(2, n + 1): if prime[p]: x.append(p) return x s = int(N**0.5) p = SieveOfEratosthenes(s) t = 0 for i in range(len(p)): if p[i] ** 4 <= s: t += 1 for j in range(i + 1, len(p)): if p[i] * p[j] <= s: t += 1 else: break return t
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
N = 150000 dp = [(0) for i in range(150000)] primes = [] primes2 = [] for i in range(2, 150000): for j in range(i * i, 150000, i): dp[j] = 1 if not dp[i]: primes.append(i) primes2.append(i * i) def bs(i, j, k): if i > j: return j m = (i + j) // 2 if k < primes2[m]: return bs(i, m - 1, k) return bs(m + 1, j, k) class Solution: def nineDivisors(self, N): s = 0 for p in primes2: if p**4 <= N: s += 1 else: break for p in primes2: if p * 4 > N: break x = bs(0, len(primes2) - 1, min(N / p, p - 1)) s += x + 1 return s if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class PrimeNumbers: def prime_numbers(lower, upper, plist, slist): for num in range(lower, upper + 1): if num > 1: for i in range(2, num): if num % i == 0: break else: plist.append(num) slist.append(num * num) class Solution: def nineDivisors(self, N): c = 0 limit = int(N**0.5) prime = [i for i in range(limit + 1)] i = 2 while i * i <= limit: if prime[i] == i: for j in range(i * i, limit + 1, i): if prime[j] == j: prime[j] = i i += 1 for i in range(2, limit + 1): p = prime[i] q = prime[i // prime[i]] if p * q == i and q != 1 and p != q: c += 1 elif prime[i] == i: if i**8 <= N: c += 1 return c def nineDivisors_gen(self, N): primes = [] squares = [] PrimeNumbers.prime_numbers(0, 2000, primes, squares) epower = [2**8, 3**8, 5**8, 7**8, 11**8, 13**8, 17**8] divisors = 0 i = 0 while i < len(squares) - 1 and squares[i] * squares[i + 1] <= N: j = i + 1 while j < len(squares) and squares[i] * squares[j] <= N: divisors += 1 j += 1 i += 1 i = 0 while i < len(epower) and epower[i] <= N: divisors += 1 i += 1 return divisors if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER VAR VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
class Solution: def nineDivisors(self, N): k = int(N**0.5) primes = [(1) for i in range(k + 1)] primes[0] = 0 primes[1] = 0 for i in range(2, k + 1): if primes[i]: for j in range(i * i, k + 1, i): primes[j] = 0 curr = [] for i in range(len(primes)): if not curr: curr.append(primes[i]) else: curr.append(curr[-1] + primes[i]) res = 0 for i in range(int(len(primes))): if primes[i]: a = int(N**0.5 / i) res += max(curr[a] - curr[i], 0) res += curr[int(N ** (1 / 8))] return res if __name__ == "__main__": t = int(input()) for _ in range(t): N = int(input()) ob = Solution() print(ob.nineDivisors(N))
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Find the count of numbers less than equal to N having exactly 9 divisors. Example 1: Input: N = 100 Output: 2 Explanation: The two numbers which have exactly 9 divisors are 36 and 100. Example 2: Input: N = 1000 Output: 8 Explanation: The numbers are: 36 100 196 225 256 441 484 676 Your Task: You don't need to read input or print anything. Your task is to complete the function nineDivisors() which takes an integer N as an input parameter and returns the total number of elements from 1 to N inclusive, that have exactly 9 divisors. Expected Time Complexity: O(sqrt(Nlog(logN))) Expected Auxiliary Space: O(sqrt(N)) Constraints: 1<=N<=10^{10}
primes = [2] prime = [1] * 100001 for i in range(4, 100001, 2): prime[i] = 0 for i in range(3, 100001, 2): if prime[i]: for j in range(i * i, 100001, i): prime[j] = 0 primes.append(i) m = len(primes) class Solution: def nineDivisors(self, n): ans = 0 for i in range(m): x = primes[i] * primes[i] if x >= n: break if pow(x, 4) <= n: ans += 1 l = 0 r = i - 1 while l <= r: mid = (l + r) // 2 z = primes[mid] * primes[mid] * x if z <= n: l = mid + 1 else: r = mid - 1 ans += l return ans
ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def testcase(): [X, Y] = [int(c) for c in input().split()] res = 0 b = 1 while b**2 - 1 <= X and b <= Y: res += b - 1 b += 1 c = 1 while c < b: hi = X // c - 1 lo = (X + c + 1) // (c + 1) - 1 res += c * max(min(Y, hi) - max(b, lo) + 1, 0) c += 1 print(res) T = int(input()) for i in range(T): testcase()
FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
for _ in range(int(input())): a, b = map(int, input().split()) s = 0 i = 1 while True: t = min(b, (a - i) // i) - i if t > 0: s += t else: break i += 1 print(s)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
import sys input = sys.stdin.readline R = lambda: map(int, input().split()) I = lambda: int(input()) S = lambda: input().rstrip("\n") L = lambda: list(R()) def solve(): x, y = R() ans = 0 i = 1 while i * i <= x: temp = min(y, x // i - 1) - i ans += 0 if temp < 0 else temp i += 1 print(ans) for _ in range(I()): solve()
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def solve(): x, y = list(map(int, input().split(" "))) ans = 0 i = 1 while i * i < x: ans += max(min(y, x // i - 1) - i, 0) i += 1 print(ans) t = int(input()) for i in range(t): solve()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): x, y = map(int, input().split()) ans = 0 num = 0 ok = False while num * (num + 2) <= x: num += 1 ans += num - 1 if y == num: ok = True break if ok: print(ans) continue t = x // (num + 2) now = num + 2 while t: s = x // t if s <= y + 1: ans += t * (s - now + 1) now = s + 1 t -= 1 else: ans += t * (y + 1 - now + 1) break print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def find(): x, y = map(int, input().split()) s = 0 for j in range(1, int(x**0.5) + 1): s += max(0, min(y, x // j - 1) - j) return s for i in range(int(input())): print(find())
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
for t in range(int(input())): a, b = map(int, input().split()) ans = 0 x = int((a + 1) ** 0.5) + 2 for i in range(1, x): ans += max(0, min((a - i) // i, b) - i) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
for _ in range(int(input())): a, b = map(int, input().split()) ans = 0 for k in range(1, 31624): x = a // k - 1 y = b result = 0 if k + 1 <= b and k * (k + 2) <= a: if x < y: result = x - k else: result = y - k else: break ans += result print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
t = int(input()) for _ in range(t): x, y = (int(i) for i in input().split()) k, res = 1, 0 while True: temp = min(x // k - k - 1, y - k) if temp <= 0: break res += temp k += 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
import sys def main(): t = int(input()) allAns = [] for _ in range(t): x, y = readIntArr() ans = 0 nK = 1 while min(x // nK - 1, y) >= nK: ans += min(x // nK - 1, y) - nK nK += 1 allAns.append(ans) multiLineArrayPrint(allAns) return input = lambda: sys.stdin.readline().rstrip("\r\n") def oneLineArrayPrint(arr): print(" ".join([str(x) for x in arr])) def multiLineArrayPrint(arr): print("\n".join([str(x) for x in arr])) def multiLineArrayOfArraysPrint(arr): print("\n".join([" ".join([str(x) for x in y]) for y in arr])) def readIntArr(): return [int(x) for x in input().split()] inf = float("inf") MOD = 10**9 + 7 main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
T = int(input()) for t in range(T): x, y = tuple([int(x) for x in input().split()]) sqrt_x = int(x**0.5) result = 0 for i in range(1, sqrt_x + 1): num_n = min(x // i, y + 1) - i - 1 if num_n <= 0: break result += num_n print(result)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
t = int(input()) for i in range(t): l1 = input().split(" ") x, y = int(l1[0]), int(l1[1]) s = 0 for j in range(1, y): k = (x - j) // j if k <= j: break s += min(k, y) - j j += 1 print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
a = int(input()) for i in range(a): x, y = map(int, input().split()) flag = 0 save = 0 total = 0 rem = 1 while (rem + 1) * rem + rem <= x and rem < y: q = (x - rem) // rem q = min(y, q) total += q - (rem + 1) + 1 rem += 1 print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
for _ in range(int(input())): a, b = map(int, input().split()) k = 2 ost = 1 p = min(a // ost - k, b - k + 1) c = 0 while p > 0: k += 1 c += p ost += 1 p = min(a // ost - k, b - k + 1) print(c)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def solve(y, x): ct = 0 for i in range(1, 100000): mx = i + 1 my = i * (mx + 0) z = min(x - mx + 1, (y - my) // i) if z < 0: break ct += z return ct t = int(input()) for _ in range(t): x, y = [int(i) for i in input().split()] print(solve(x, y))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
for _ in range(int(input())): x, y = list(map(int, input().split())) s = 0 for i in range(1, min(x - 1, y)): c = x // i - 1 if c <= i: break s += min(c, y) - i print(s)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def answer(): ans = 0 for i in range(1, b + 1): val = min(a // i, b + 1) - i - 1 if val <= 0: break ans += val return ans for T in range(int(input())): a, b = map(int, input().split()) print(answer())
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
import sys input = sys.stdin.buffer.readline for t in range(int(input())): X, Y = map(int, input().split()) Z = min(Y, int(X**0.5) + 1) ANS = 0 for i in range(1, min(Z + 1, Y) + 1): A = X // (i + 1) ANS += min(A, i - 1) if Z + 1 >= Y: print(ANS) continue for i in range(1, int(X**0.5) + 3): B = X // i if B <= Z + 1: break ANS += max(0, min(B - 1, Y) - Z - 1) print(ANS)
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
from sys import stdin input = stdin.readline def calc(n): return n * (n - 1) + n - 1 def cal(n, deg): return n * deg + deg def bin(x): start = 1 end = x while start <= end: mid = (start + end) // 2 if calc(mid) <= x < calc(mid + 1): return mid elif calc(mid) <= x and calc(mid + 1) <= x: start = mid + 1 else: end = mid - 1 return start def nbin(x, deg): start = 1 end = x while start <= end: mid = (start + end) // 2 if cal(mid, deg) <= x < cal(mid + 1, deg): return mid elif cal(mid, deg) <= x and cal(mid + 1, deg) <= x: start = mid + 1 else: end = mid - 1 return start for _ in range(int(input())): x, y = map(int, input().split()) a = bin(x) if a >= y: print(y * (y - 1) // 2) else: ans = a * (a - 1) // 2 deg = a while a < y and deg > 0: deg -= 1 newa = nbin(x, deg) if newa < y: ans += deg * (newa - a) else: ans += deg * (y - a) a = newa print(ans)
ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
from sys import stdin t = int(stdin.readline()) for _ in range(t): a, b = map(int, stdin.readline().split()) ans = 0 d = 1 while d * (d + 2) <= a: x = a // d - (d + 1) y = b - d ans += max(0, min(x, y)) d += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
import sys input = sys.stdin.readline t = int(input()) while t > 0: x, y = map(int, input().split()) a = 0 j = 2 while j <= y: if j * j - 1 <= x: a += j - 1 j += 1 else: k = x // j if k * j + k > x: k -= 1 if k == 0: break l = (x - k) // k m = min(y, l) a += k * (m - j + 1) j = m + 1 print(a) t -= 1
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
for i in range(int(input())): a, b = map(int, input().split()) sumo = 0 for j in range(1, b + 1): if a // j <= j + 1 or b - j <= 0: break sumo = sumo + min(a // j - 1, b) - j print(sumo)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
import sys input = sys.stdin.readline def solve(): x, y = map(int, input().split()) if x < 3 or y < 2: return 0 ans = 0 for i in range(3, min(10**5 + 4, y + 2)): if i * (i - 2) > x: break ans += min(x // (i - 2), y + 1) - i + 1 return ans for _ in range(int(input())): print(solve())
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
al = [] for _ in range(int(input())): x, y = map(int, input().split()) ans = 0 for r in range(1, x): if r * r >= x: break cmin = r + 2 cmax = min(x // r, y + 1) cnt = cmax - cmin + 1 ans += max(0, cnt) al.append(ans) for a in al: print(a)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
for _ in range(int(input())): x, y = map(int, input().split()) ans, i = 0, 1 while i * i <= x: ans, i = ans + max(0, min(y, x // i - 1) - i), i + 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
t = int(input()) for _ in range(t): x, y = map(int, input().split()) ans = 0 a = 3 for b in range(2, y + 1): if x - a < 0: break z = min(y - b + 1, (x - a) // (b - 1) + 1) a += 2 * b + 1 ans += z print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def f(max_a, max_b): b_q = floor_sqrt(max_a) b_n_fst = min(b_q, max_b) variants_n_fst = b_n_fst * (b_n_fst + 1) // 2 + -1 * b_n_fst if b_q >= max_b: variants_n_snd = 0 else: variants_n_snd = p(max_a, max_b + 2 - 1) - p(max_a, b_q + 2 - 1) return variants_n_fst + variants_n_snd def p(x, max_div): max_div = min(max_div, x) min_div_result_to_take = floor_sqrt(x) result = __p_brute(x, max_div, min_div_result_to_take) min_div_result_possible = x // max_div if min_div_result_possible >= min_div_result_to_take: return result max_d = max_div min_d = 1 while min_d != max_d: mid_d = (min_d + max_d) // 2 if x // mid_d == min_div_result_possible: max_d = mid_d else: min_d = mid_d + 1 result += (max_div - min_d + 1) * min_div_result_possible for div_res in range(min_div_result_possible + 1, min_div_result_to_take): result += (x // div_res - x // (div_res + 1)) * div_res return result def __p_brute(x, max_div, min_res_to_take): max_div = min(max_div, x) result = 0 for d in range(1, max_div + 1): div_res = x // d if div_res < min_res_to_take: break result += div_res return result def floor_sqrt(x): assert x >= 0 min_sqrt = 0 max_sqrt = max(x, 1) while min_sqrt != max_sqrt: mid_sqrt = (min_sqrt + max_sqrt + 1) // 2 if mid_sqrt**2 <= x: min_sqrt = mid_sqrt else: max_sqrt = mid_sqrt - 1 return min_sqrt def read_ints(): return map(int, input().split()) (t_n,) = read_ints() for i_t in range(t_n): x, y = read_ints() result = f(x, y) print(result)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR RETURN VAR FUNC_DEF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
for _ in range(int(input())): a, b = map(int, input().split()) cr, ans, mn = b - 1, 0, 2 i = 1 while mn * i + i <= a and mn <= b: tp = (a - i) // i ans += min(tp - mn + 1, cr) cr -= 1 mn += 1 i += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
t = int(input()) for _ in range(t): a, b = map(int, input().split(" ")) count = 0 k = int(a**0.5) + 1 for i in range(1, k + 1): s = int(a / i) s = min(s, b + 1) count += max(0, s - i - 1) print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def main(): t = int(input()) ans = [] for _ in range(t): x, y = map(int, input().split()) x = min(y * y, x) y = min(x - 1, y) cnt = 0 rem = 1 while rem * rem <= x: cnt += max(0, min(y, x // rem - 1) - rem) rem += 1 ans.append(str(cnt)) print("\n".join(ans)) def tests(): a = 10000 b = 12 a = min(b * b, a) b = min(a - 1, b) cnt = 0 for cb in range(2, b + 1): pairs = [] for ca in range(2, a + 1): x = ca // cb y = ca % cb if x == y: pairs.append((ca, cb)) print(pairs) cnt += len(pairs) print(f"cnt = {cnt}") print(f"sum = {sum(range(b))}") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def main(): t = int(input()) for _ in range(t): x, y = map(int, input().split()) total = 0 for i in range(1, int(x**0.5) + 1): maxx = min(i * y + i, x) total += max(0, maxx // i - (i + 1)) print(total) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
import sys from sys import stdin tt = int(stdin.readline()) for loop in range(tt): x, y = map(int, stdin.readline().split()) ans = 0 for c in range(1, x): now = min(y, x // c - 1) if now > c: ans += now - c else: break print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
import sys input = sys.stdin.readline def binarySearch(num, highest, denom): low = denom high = highest floorDiv = num // denom best = denom while low <= high: mid = (low + high) // 2 if num // mid == floorDiv: best = mid low = mid + 1 else: high = mid - 1 delta = best - denom + 1 addToResult = delta * floorDiv return addToResult, best + 1 t = int(input()) for _ in range(t): x, y = map(int, input().split()) num = 1 result = 0 while num * num <= x and num <= y: result += num - 1 num += 1 denom = num + 1 while denom <= y + 1: addToResult, denom = binarySearch(x, y, denom) result += addToResult print(result)
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def solve(x, y): res = 0 r = 1 while r * (r + 2) <= x: res += max(0, min(y, x // r - 1) - r) r += 1 return res t = int(input()) for _ in range(t): x, y = map(int, input().split()) print(solve(x, y))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $1\leq a \leq x$ and $1 \leq b \leq y$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The only line of the description of each test case contains two integers $x$, $y$ ($1 \le x,y \le 10^9$). -----Output----- For each test case print the answer on a single line. -----Examples----- Input 9 3 4 2 100 4 3 50 3 12 4 69 420 12345 6789 123456 789 12345678 9 Output 1 0 2 3 5 141 53384 160909 36 -----Note----- In the first test case, the only special pair is $(3, 2)$. In the second test case, there are no special pairs. In the third test case, there are two special pairs: $(3, 2)$ and $(4, 3)$.
def array(f): return list(map(f, input().split())) def floor_sum(X, N): res = 0 for i in range(X // N, X + 1): if i * i > X: for j in range(1, N + 1): if X // j >= i: res += X // j else: break break if i == 0: continue n = min(X // i, N) - X // (i + 1) res += n * i return res def slv(): x, y = map(int, input().split()) ans = 0 for b in range(1, y + 1): if x // (b + 1) >= b - 1: ans += b - 1 else: ans += floor_sum(x, y + 1) - floor_sum(x, b) break print(ans) return def main(): T = int(input()) for _ in range(T): slv() main()
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR