description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for T in range(t): n = int(input()) l = [0, n] st = set(l) for i in range(1, int(n**0.5) + 1): st.add(i) st.add(n // i) print(len(st)) print(*sorted(st))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for _ in range(t): n = int(input()) b = set([]) for i in range(1, n + 2): if n // i not in b: b.add(n // i) else: b = sorted(list(b), reverse=True) for i in range(b[-1] - 1, -1, -1): b.append(i) break print(len(b)) b = sorted(list(b)) print(*b)
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 LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
from sys import stdin input = stdin.readline for _ in range(int(input())): n = int(input()) v = [n] if n == 1: print(2) print(0, 1) else: l = 2 p = r = n // 2 + 1 v += (n // 2,) ans = n // 2 ans1 = ans while ans != 1: r = p while l <= r: m = (l + r) // 2 s = n // m if s < ans: ans1 = s r = m - 1 else: l = m + 1 v += (ans1,) ans = ans1 v += (0,) print(len(v)) print(*v[::-1])
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
for i in range(int(input())): n = int(input()) m = int(n**0.5) print(2 * m + (m != n // m)) l = [i for i in range(m)] s = " " + str(m) + " " + ("" if m == n // m else str(n // m) + " ") li = [str(n // i) for i in l[:0:-1]] print(" ".join([str(i) for i in l]) + s + " ".join(li))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING VAR BIN_OP VAR VAR STRING BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL STRING VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
import sys input = sys.stdin.readline def divisors(n): res = [] for i in range(1, int(n**0.5) + 1): res.append(i) res.append(n // i) return res for _ in range(int(input())): n = int(input()) s = set() for i in divisors(n): s.add(i) s.add(0) print(len(s)) print(*sorted(s))
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN 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 FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
tc = int(input()) for _ in range(tc): x = int(input()) ans = set() ans.add(0) for i in range(1, x + 1): tee = x // i if tee not in ans: ans.add(tee) ans.add(x // tee) else: break ans = list(sorted(list(ans))) print(len(ans)) print(*ans)
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
for i in range(int(input())): n = int(input()) st = set() ans = [0] st.add(0) num = n while num >= 1: if n // num not in st: st.add(n // num) ans.append(n // num) num -= 1 else: num = (n + ans[-1]) // (ans[-1] + 1) if n // num not in st: st.add(n // num) ans.append(n // num) num -= 1 else: num -= 1 print(len(ans)) print(" ".join(map(str, ans)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) while t: s = set() l = [] n = int(input()) for i in range(1, 10**5): s.add(n // i) s = list(s) s.sort() for i in range(s[0]): l.append(i) print(len(s) + len(l)) print(*(l + s)) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 for _ in range(INT()): N = INT() A = [] prev = -1 for i in range(1, N + 1): a = N // i if a == prev: for j in range(a - 1, 0, -1): A.append(j) break A.append(a) prev = a A.append(0) print(len(A)) print(*A[::-1])
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def main(): t = int(input()) for _ in range(t): n = int(input()) k = 1 a = [] while True: p = n // k a.append(p) if p == 0: break k = n // p k += 1 a.sort() print(len(a)) print(*a) return main()
FUNC_DEF 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 LIST WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def main(): t = int(input()) for _ in range(t): n = int(input()) k = n a = [0] while True: if k == 0: break p = n // k a.append(p) l = 1 r = k ans = -1 while l <= r: m = (l + r) // 2 if n // m == p: ans = m r = m - 1 else: l = m + 1 k = ans - 1 print(len(a)) print(*a) return main()
FUNC_DEF 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 ASSIGN VAR LIST NUMBER WHILE NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for _ in range(t): x = 1 res = [] n = int(input()) while n // x != 0: res.append(n // x) x = 1 + n // (n // x) res.append(0) print(len(res)) print(*res[::-1], sep=" ", end="\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING STRING
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
q = int(input()) for ifwfwe in range(q): n = int(input()) i = 1 odp = [0] while i * i <= n: odp.append(i) i += 1 while i > 0: if n // i > odp[-1]: odp.append(n // i) i -= 1 print(len(odp)) print(*odp)
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 LIST NUMBER WHILE BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for _ in range(t): n = int(input()) l = [n] test = 2 while n // test != l[-1]: l.append(n // test) test += 1 while l[-1] != 0: l.append(l[-1] - 1) print(len(l)) print(" ".join(map(str, l[::-1])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER WHILE VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for i in range(t): ans = 0 n = int(input()) s = set([0]) ans = [0] i = n while i > 0: tmp = n // i if tmp not in s: s.add(tmp) ans.append(tmp) i = min(n // (tmp + 1), i - 1) print(len(ans)) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def oneLineArrayPrint(arr): print(" ".join([str(x) for x in arr])) def solve(n): i = 1 ans = [n] while i < n + 2: b = n while b > 0: while i + b < n + 2 and n // (i + b) == ans[-1]: i += b b //= 2 i += 1 ans.append(n // i) ans = sorted(list(set(ans))) return ans t = int(input()) for _ in range(t): n = int(input()) ans = solve(n) print(len(ans)) oneLineArrayPrint(ans)
FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
for _ in range(int(input())): l = {0} a = int(input()) for j in range(1, 1 + int(a**0.5)): l.add(j) l.add(a // j) print(len(l)) l = sorted(list(l)) for i in l: print(i, end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def main(): ans = [] n = int(input()) k = 1 ans.append(n) while k <= 10**6: k += 1 if ans[-1] > n // k: ans.append(n // k) k = 1 if n >= 10**6: for i in range(1000, -1, -1): if ans[-1] > i: ans.append(i) print(len(ans)) for i in range(len(ans) - 1, -1, -1): print(ans[i], end=" ") print() a = int(input()) for i in range(a): main()
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR BIN_OP NUMBER NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
for _ in range(int(input())): n = int(input()) ans1 = [] ans2 = [] i = 1 while i <= n**0.5: k = n // i ans1.append(k) ans2.append(i) i += 1 if ans1[-1] == ans2[-1]: ans1.pop() print(len(ans1) + len(ans2) + 1) print(0, end=" ") for i in ans2: print(i, end=" ") for i in ans1[::-1]: print(i, end=" ") print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
nn = int(input()) for i in range(nn): n = int(input()) c = 0 m = set() m.add(c) for i in range(1, int(n**0.5) + 1): m.add(n // i) m.add(i) l = sorted(m) print(len(l)) for i in l: print(i, end=" ") print()
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 EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for i in range(t): n = int(input()) ans = set() a, b = 1, n while a <= b: ans.add(a) ans.add(b) a += 1 b = n // a ans.add(0) print(len(ans)) print(*sorted(ans))
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 ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
for i in range(int(input())): n = int(input()) m = n + 1 l = {0} while m >= 1: x = n // m m = n // (x + 1) l.add(x) l = sorted(l) print(len(l)) print(*l)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
for step in range(int(input())): n = int(input()) left = [1] right = [n] i = 2 while abs(left[-1] - right[-1]) > 1 and i <= n // 2 and i <= n // i: left.append(i) right.append(n // i) i += 1 Ans = "0 " if left[-1] - right[-1] == 0: print(1 + len(left) + len(right) - 1) for i in left: Ans += str(i) + " " for i in reversed(range(len(right) - 1)): Ans += str(right[i]) + " " else: print(1 + len(left) + len(right)) for i in left: Ans += str(i) + " " for i in reversed(right): Ans += str(i) + " " print(Ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) while t: n = int(input()) ans1 = [0] ans2 = [] i = 1 while i * i <= n: if n // i != i: ans1.append(i) ans2.append(n // i) else: ans1.append(i) i += 1 ans = ans1 + ans2[::-1] print(len(ans)) print(*ans) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for ij in range(0, t): n = int(input()) ans = [0] ans1 = [] for i in range(1, int(pow(n, 0.5)) + 1): ans.append(i) for i in range(1, int(pow(n, 0.5)) + 1): ans1.append(n // i) if ans[-1] == ans1[-1]: ans.pop(-1) for i in range(len(ans1) - 1, -1, -1): ans.append(ans1[i]) print(len(ans)) for i in ans: print(i, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def main(): def solve(): n = int(input()) res = [n] v = n i = 1 while v > 1: v = n // (i + 1) res.append(v) i = n // v res.append(0) print(len(res)) print(" ".join(map(str, reversed(res)))) q = int(input()) for _ in range(q): solve() main()
FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
n = int(input()) for i in range(n): k = int(input()) srt = int(k**0.5) base = [p for p in range(srt + 1)] res = [(k // j) for j in range(srt, 0, -1)] if srt == res[0]: res = base + res[1:] else: res = base + res print(len(res)) print(" ".join(map(str, res)))
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 BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def bin_s(z, a): lo = 1 hi = z k = a // z ans = 1 while lo <= hi: mid = (lo + hi) // 2 if a // mid == k: ans = mid hi = mid - 1 else: lo = mid + 1 return ans for _ in " " * int(input()): a = int(input()) z = a + 1 f = [] while z > 0: k = bin_s(z, a) f.append(a // z) z = k - 1 print(len(f)) print(*f)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP 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 ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def rating(n): ans = [] p = 0 for i in range(0, int(n**0.5) + 1): ans.append(i) if n // int(n**0.5) == int(n**0.5): p = 1 for i in range(p, int(n**0.5)): ans.append(n // (int(n**0.5) - i)) if ans[len(ans) - 1] != n: ans.append(n) return ans n = int(input()) res = [] for i in range(n): a = int(input()) res.append(rating(a)) for j in res: tmp = len(j) tmp3 = str(j).strip("[]").replace(",", "") print(tmp) print(tmp3)
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR STRING STRING STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def solve(n): ls = [n] cur = n for _ in range(100000): low = 1 high = n + 1 while low + 1 < high: mid = (low + high) // 2 if n // mid < cur: high = mid else: low = mid cur = n // high ls.append(cur) blah = sorted(set(ls)) print(len(blah)) print(" ".join(map(str, blah))) for _ in range(int(input())): solve(int(input()))
FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
for _ in range(int(input())): n = int(input()) a = [0, 1, n] d = 2 while d * d <= n: a += (d,) a += (n // d,) d += 1 a = sorted(set(a)) print(len(a)) print(" ".join(map(str, a)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def solve(): n = int(input()) s = set() s.add(0) for i in range(1, int(n**0.5) + 1): k = n // i s.add(k) s.add(i) ans = sorted(s) print(len(ans)) print(*ans) t = int(input()) for i in range(t): solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
q = int(input()) for _ in range(q): n = int(input()) a = [0] b = [] if n == 1: print(2) print(0, 1) else: t = 1 for i in range(1, int(n**0.5) + 1): if i * i <= n: a.append(i) l = i b.append(n // i) b = b[::-1] if b[0] == l: print(len(a) + len(b) - 1) else: print(len(a) + len(b)) for t in a: print(t, end=" ") if l != b[0]: print(b[0], end=" ") for t in b[1:]: print(t, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for _ in range(t): n = int(input()) ans = [] ans.append(0) ans.append(1) ans.append(n) for i in range(2, int(n**0.5) + 1): ans.append(n // i) ans.append(n // (n // i)) ans = set(ans) ans = list(ans) ans.sort() print(len(ans)) for i in ans: print(i, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
import sys def I(): return sys.stdin.readline().rstrip() for _ in range(int(I())): n = int(I()) a = [0, 1] i = n while i > 0: if n // i > a[-1]: a.append(n // i) i = n // (a[-1] + 1) print(len(a)) print(*a)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) while t != 0: n = int(input()) p = int(pow(n, 0.5)) + 1 list1 = list() for i in range(1, p): if n % i == 0: list1.append(i) list1.append(n // i) else: list1.append(n // i) list1.append(i) list1.append(0) list1 = list(set(list1)) print(len(list1)) list1.sort() for j in range(len(list1)): print(list1[j], end=" ") print() t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
for _ in range(int(input())): n = int(input()) ar1 = [] ar2 = [0] count = 1 for k in range(1, int(n ** (1 / 2)) + 1): p = n // k if p != k and n % k <= p: count += 2 ar1.append(p) ar2.append(k) elif p == k and n % k <= p: count += 1 ar1.append(p) print(count) print(*(ar2 + ar1[::-1]))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for __ in range(t): n = int(input()) ms = {n} prev_m = n rem = 0 k = 2 while prev_m != 0: if rem < prev_m: prev_m = n // k rem = n - prev_m * k ms.add(prev_m) k += 1 else: k += rem // prev_m rem %= prev_m ms = list(ms) ms.sort() print(len(ms)) print(" ".join(map(str, ms)))
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 ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
import sys input = lambda: sys.stdin.readline().rstrip() t = int(input()) for _ in range(t): n = int(input()) ans = [0] while ans[-1] < n: ok = 0 ng = n + 1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if n // mid > ans[-1]: ok = mid else: ng = mid ans.append(n // ok) print(len(ans)) print(*ans)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL 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 LIST NUMBER WHILE VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
for _ in range(int(input())): n, s = int(input()), {0} for d in range(1, n + 1): if n // d in s: break s.update((d, n // d)) print(len(s)) print(" ".join(str(i) for i in sorted(s)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
t = int(input()) for _ in range(t): n = int(input()) s = set.union({0}, *({i, n // i} for i in range(1, int(n**0.5) + 1))) print(len(s)) for v in sorted(s): print(v, end=" ") print()
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 NUMBER VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
On the well-known testing system MathForces, a draw of $n$ rating units is arranged. The rating will be distributed according to the following algorithm: if $k$ participants take part in this event, then the $n$ rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants. For example, if $n = 5$ and $k = 3$, then each participant will recieve an $1$ rating unit, and also $2$ rating units will remain unused. If $n = 5$, and $k = 6$, then none of the participants will increase their rating. Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help. For example, if $n=5$, then the answer is equal to the sequence $0, 1, 2, 5$. Each of the sequence values (and only them) can be obtained as $\lfloor n/k \rfloor$ for some positive integer $k$ (where $\lfloor x \rfloor$ is the value of $x$ rounded down): $0 = \lfloor 5/7 \rfloor$, $1 = \lfloor 5/5 \rfloor$, $2 = \lfloor 5/2 \rfloor$, $5 = \lfloor 5/1 \rfloor$. Write a program that, for a given $n$, finds a sequence of all possible rating increments. -----Input----- The first line contains integer number $t$ ($1 \le t \le 10$) — the number of test cases in the input. Then $t$ test cases follow. Each line contains an integer $n$ ($1 \le n \le 10^9$) — the total number of the rating units being drawn. -----Output----- Output the answers for each of $t$ test cases. Each answer should be contained in two lines. In the first line print a single integer $m$ — the number of different rating increment values that Vasya can get. In the following line print $m$ integers in ascending order — the values of possible rating increments. -----Example----- Input 4 5 11 1 3 Output 4 0 1 2 5 6 0 1 2 3 5 11 2 0 1 3 0 1 3
def solve(): n = int(input()) i = 1 l = [0] m = [] sqrt = n**0.5 while i <= sqrt: k = n // i m.append(k) l.append(i) i += 1 if l[-1] == m[-1]: l.pop() print(len(l) + len(m)) for i in l: print(i, end=" ") for i in range(len(m) - 1, -1, -1): print(m[i], end=" ") print() t = int(input()) for _ in range(t): solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def possible(m): left_contiguous_idx, right_contiguous_idx, flips = 0, 0, 0 for i in range(n): if s[left_contiguous_idx] == s[right_contiguous_idx]: right_contiguous_idx += 1 else: flips += (right_contiguous_idx - left_contiguous_idx) // (m + 1) left_contiguous_idx = right_contiguous_idx right_contiguous_idx += 1 flips += (right_contiguous_idx - left_contiguous_idx) // (m + 1) return flips <= k for _ in range(int(input().strip())): n, k = map(int, input().strip().split()) s = [int(i) for i in input().strip()] s_copy_0 = s[:] s_copy_1 = s[:] s_copy_1[0] = 1 - s_copy_1[0] count_0 = 0 count_1 = 1 for i in range(1, n): if s_copy_0[i] == s_copy_0[i - 1]: s_copy_0[i] = 1 - s_copy_0[i - 1] count_0 += 1 if s_copy_1[i] == s_copy_1[i - 1]: s_copy_1[i] = 1 - s_copy_1[i - 1] count_1 += 1 if min(count_1, count_0) <= k: print(1) else: ans = n l = 2 r = n while l < r: m = (l + r) // 2 if possible(m): r = m else: l = m + 1 print(r)
FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
t = int(input()) for i in range(t): length, swaps = map(int, input().split()) seq = list(input()) one = False temp = 0 for j in range(length): if j % 2 == 0: if seq[j] != "1": temp += 1 elif seq[j] != "0": temp += 1 if temp > swaps: break if temp <= swaps: one = True else: temp = 0 for j in range(length): if j % 2 == 0: if seq[j] != "0": temp += 1 elif seq[j] != "1": temp += 1 if temp > swaps: break if temp <= swaps: one = True if not one: blocks = [] last = seq[0] counter = 1 for k in seq[1:]: if k == last: counter += 1 else: blocks.append(counter) counter = 1 last = k blocks.append(counter) ll = 2 ul = max(blocks) while ll <= ul: mid = ll + (ul - ll) // 2 tempswaps = 0 for a in blocks: tempswaps += a // (mid + 1) if tempswaps > swaps: ll = mid + 1 elif tempswaps <= swaps: ul = mid - 1 print(ll) elif one: print(1)
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def is_valid(arr, k, lim): cnt = 0 curr = arr[0] for x in arr: if x != curr: req = cnt // (lim + 1) if req > k: return False else: k -= req cnt = 0 curr = x cnt += 1 req = cnt // (lim + 1) if req > k: return False else: k -= req return True for inp in range(int(input())): N, K = [int(x) for x in input().strip().split()] arr = input().strip() ans = N low, high = 2, N while low <= high: mid = (low + high) // 2 if is_valid(arr, K, mid): ans = mid high = mid - 1 else: low = mid + 1 if ans == 2: odd = arr[::2] even = arr[1::2] mink = min(odd.count("1") + even.count("0"), odd.count("0") + even.count("1")) if mink <= K: ans = 1 print(ans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER 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 ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def reverse_insort(a, x, lo=0, hi=None): if lo < 0: raise ValueError("lo must be non-negative") if hi is None: hi = len(a) try: while lo < hi: mid = (lo + hi) // 2 if x[0] > a[mid][0]: hi = mid elif x[0] < a[mid][0]: lo = mid + 1 elif x[2] > a[mid][2]: hi = mid else: lo = mid + 1 except: a.append(x) a.sort(key=lambda x: (x[0], x[2]), reverse=True) return a.insert(lo, x) def get_counts(s, n): counts = [] current_count = 0 prev = None for i in range(n): if s[i] == prev: current_count += 1 else: if current_count > 1: counts.append(current_count) current_count = 1 prev = s[i] if current_count > 1: counts.append(current_count) counts.sort(reverse=True) return counts def check_for_one(n, k, s): start_with_one = 0 start_with_zero = 0 for i in range(n): if i % 2 == int(s[i]): start_with_zero += 1 else: start_with_one += 1 return ( start_with_zero == 0 or start_with_one == 0 or min(start_with_zero, start_with_one) <= k ) t = int(input().replace(" ", "")) while t: t -= 1 inputs = list(map(int, input().strip().split())) n = inputs[0] k = inputs[1] s = list(input().replace(" ", "")) if k >= n or check_for_one(n, k, s): print(1) continue counts = get_counts(s, n) op_counts = [{(0): count, (1): 0, (2): count} for count in counts] if len(op_counts) == 1: print(max(2, op_counts[0][2] // (k + 1))) continue if op_counts[0][0] == 2 or k == 0: print(max(2, op_counts[0][0])) continue for i in range(k): if op_counts[0][0] == 2: break else: op_counts[0][1] += 1 op_counts[0][0] = op_counts[0][2] // (op_counts[0][1] + 1) curr_e = op_counts[0] op_counts = op_counts[1:] reverse_insort(op_counts, curr_e) print(max(2, int(op_counts[0][0])))
FUNC_DEF NUMBER NONE IF VAR NUMBER FUNC_CALL VAR STRING IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING STRING WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING STRING IF VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def possible(a, mid, k): cnt = 0 for i in a: cnt += i // (mid + 1) return cnt <= k for _ in range(int(input())): n, k = map(int, input().split()) a = [] s = list(input()) cur = 1 for i in range(1, n): if s[i] != s[i - 1]: a.append(cur) cur = 1 else: cur += 1 a.append(cur) k = min(k, n) c1 = 0 c2 = 0 for i in range(n): if int(s[i]) == 0: if i % 2 == 0: c1 += 1 else: c2 += 1 elif i % 2 == 1: c1 += 1 else: c2 += 1 if c1 <= k or c2 <= k: print(1) continue low = 2 high = n ans = n while low <= high: mid = (low + high) // 2 if possible(a, mid, k): ans = mid high = mid - 1 else: low = mid + 1 print(ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN 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 LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN 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 ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
cases = int(input()) for _ in range(cases): n, k = list(map(int, input().split())) s = input().strip() def getans(): s1 = s2 = "" cost1 = cost2 = 0 c = 1 for i in range(n): s1 += str(c) s2 += str(1 - c) c = 1 - c for i in range(n): if s[i] != s1[i]: cost1 += 1 if s[i] != s2[i]: cost2 += 1 if k >= min(cost1, cost2): return 1 blocks = [] c = 1 for i in range(1, n): if s[i] == s[i - 1]: c += 1 else: blocks.append(c) c = 1 if c > 0: blocks.append(c) lo, hi = 1, n while lo < hi: mid = (lo + hi) // 2 cost = 0 for i in blocks: cost += i // (mid + 1) if cost > k: lo = mid + 1 else: hi = mid if lo == 1: lo += 1 return lo print(getans())
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def check(mid): count = 0 for i in arr: count += i // (mid + 1) return count def get(s, n, k): low, high = 2, n while low < high: mid = (low + high) // 2 if check(mid) <= k: high = mid else: low = mid + 1 return low for _ in range(int(input())): n, k = map(int, input().split()) s = input() f1, f0 = 1, 0 tot1, tot0 = 0, 0 for i in range(n): if f1 != int(s[i]): tot0 += 1 if f0 != int(s[i]): tot1 += 1 f0, f1 = f0 ^ 1, f1 ^ 1 if min(tot0, tot1) <= k: print(1) continue last, arr, count = s[0], [], 1 for i in range(1, n): if s[i] == last: count += 1 else: last = s[i] arr.append(count) count = 1 arr.append(count) print(get(s, n, k))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR 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 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 ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def requiredLessThanK(m): count = 0 for i in blocks: if i > m: count += i // (m + 1) return count <= k for _ in range(int(input())): n, k = map(int, input().split()) s = input() cnt = 1 blocks = [] s1 = "01" * (n // 2) s2 = "10" * (n // 2) c1 = 0 c2 = 0 if n & 1: s1 += "0" s2 += "1" for i in range(n): if s1[i] == s[i]: c1 += 1 if s2[i] == s[i]: c2 += 1 if min(c1, c2) <= k: print(1) else: for i in range(1, n): if s[i] != s[i - 1]: blocks.append(cnt) cnt = 1 else: cnt += 1 blocks.append(cnt) l = 2 r = n ans = n while l <= r: mid = (l + r) // 2 if requiredLessThanK(mid): ans = mid r = mid - 1 else: l = mid + 1 print(ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN 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 ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR STRING VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def one(A): a = sum(A[i] != i % 2 for i in range(len(A))) b = sum(A[i] != 1 - i % 2 for i in range(len(A))) return min(a, b) def calc(A, x): if x == 1: return one(A) flips = streak = 0 A = [-1] + A + [-1] for i in range(1, len(A) - 1): if A[i] != A[i - 1]: streak = 1 else: streak += 1 if streak > x: A[i] = -1 flips += 1 streak = 1 return flips for t in range(int(input())): n, k = map(int, input().split()) A = list(map(int, list(input().strip()))) lo = 1 hi = n while lo < hi: mid = (lo + hi) // 2 flips = calc(A[:], mid) if flips > k: lo = mid + 1 else: hi = mid print(hi)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN 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 FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def ispzbl(block, mid, k): c = 0 for j in block: if j > mid: c += j // (mid + 1) return c <= k t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = list(input()) block = [] count = 1 for i in range(1, n): if a[i] != a[i - 1]: block.append(count) count = 1 else: count += 1 block.append(count) s1 = "10" * (n // 2) s2 = "01" * (n // 2) if n & 1: s1 += "1" s2 += "0" cn1, cn2 = 0, 0 for i in range(n): if a[i] == s1[i]: cn1 += 1 if a[i] == s2[i]: cn2 += 1 if min(cn1, cn2) <= k: print(1) else: low, high = 2, n ans = n while low <= high: mid = (low + high) // 2 if ispzbl(block, mid, k): ans = mid high = mid - 1 else: low = mid + 1 print(ans)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR STRING VAR STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN 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 ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def can(n, s, seg): ret = 0 last = s[0] cnt = 0 for i in range(n): if last != s[i]: cnt = 1 last = s[i] else: cnt += 1 if cnt > seg: last ^= 1 if seg > 1 and i + 1 < n and s[i + 1] == last: last ^= 1 ret += 1 cnt = 1 ret2 = ret ret = 1 last = s[0] ^ 1 cnt = 1 for i in range(1, n): if last != s[i]: cnt = 1 last = s[i] else: cnt += 1 if cnt > seg: last ^= 1 if seg > 1 and i + 1 < n and s[i + 1] == last: last ^= 1 ret += 1 cnt = 1 return min(ret, ret2) def main(): for _ in range(int(input())): n, k = map(int, input().split()) s = [int(c) for c in input().strip()] l = 1 r = n while l < r: mid = (l + r) // 2 if can(n, s, mid) <= k: r = mid else: l = mid + 1 print(l) main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF 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 VAR FUNC_CALL FUNC_CALL VAR 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 VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
for _ in range(int(input())): n, k = [int(i) for i in input().split()] s = input() k1 = k2 = 0 for i in range(n): if int(s[i]) != i % 2: k1 += 1 else: k2 += 1 if k >= min(k1, k2): print(1) continue i = 0 arr = [] while i < n: arr.append(1) while i < n - 1 and s[i] == s[i + 1]: arr[-1] += 1 i += 1 i += 1 t = 0 ind = [] for i in arr: if i == 2 or i == 1: ind.append(t) t += 1 for i in ind[::-1]: arr.pop(i) for i in range(len(arr)): arr[i] = [arr[i], 1] while len(arr) != 0 and k != 0: arr.sort(key=lambda x: x[0] // x[1], reverse=True) curr = arr[0] if curr[0] // (curr[1] + 1) < 3: arr.pop(0) else: curr[1] += 1 k -= 1 if len(arr) == 0: print(2) else: maxi = -1 for i in arr: maxi = max(maxi, i[0] // i[1]) print(maxi)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def solve(s, n, k): cnt1 = 0 cnt2 = 0 for i in range(n): if i % 2 == 0: if s[i] == "1": cnt1 += 1 else: cnt2 += 1 elif s[i] == "0": cnt1 += 1 else: cnt2 += 1 if k >= min(cnt1, cnt2): print(1) return blocks = [] cnt = 1 for idx, bit in enumerate(s): if idx == n - 1: break if idx < n - 1 and s[idx] != s[idx + 1]: blocks.append(cnt) cnt = 0 cnt += 1 blocks.append(cnt) low = 2 high = n while low < high: L = int((low + high) / 2) flips = 0 for x in blocks: flips += int(x / (L + 1)) if flips <= k: high = L else: low = L + 1 print(low) t = int(input()) while t > 0: t -= 1 n, k = map(int, input().split()) s = input() solve(s, n, k)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
T = int(input()) while T: N, K = map(int, input().rstrip().rsplit()) st = str(input()) a = "01" * (N // 2) b = "10" * (N // 2) if N & 1: a += "0" b += "1" n1, n2 = 0, 0 for i in range(N): if a[i] != st[i]: n1 += 1 if b[i] != st[i]: n2 += 1 if n1 <= K or n2 <= K: print(1) else: blocks = [] count = 1 for i in range(1, N): if st[i] != st[i - 1]: blocks.append(count) count = 1 else: count += 1 blocks.append(count) l, r = 2, N while l < r: mid = (l + r) // 2 c = 0 for i in blocks: if i > mid: c += i // (mid + 1) if c > K: l = mid + 1 else: r = mid print(l) T -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR STRING VAR STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def solve(ls, l, k): for i in ls: p = len(i) if p > l: k -= p // (l + 1) if k < 0: return False return True for _ in range(int(input())): n, k = map(int, input().split()) st = input() ls = list() prev = st[0] for i in st[1:]: if i != prev[-1]: ls.append(prev) prev = i else: prev += i ls.append(prev) s1 = "10" * (n // 2) s2 = "01" * (n // 2) if n % 2 != 0: s1 += "1" s2 += "0" a = b = 0 for i in range(n): if s1[i] != st[i]: a += 1 if s2[i] != st[i]: b += 1 if min(a, b) <= k: print(1) else: l, r, res = 2, n, n while l <= r: m = l + (r - l) // 2 if solve(ls, m, k): res = min(res, m) r = m - 1 else: l = m + 1 print(res)
FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
t = int(input()) for t0 in range(t): s = [int(i) for i in input().strip().split()] n, k = s[0], s[1] a = input().strip() rc = [] p = a[0] ct = 1 reqd = 0 m = 0 for i in range(1, n): if a[i] == p: ct += 1 if m == 0: reqd += 1 m = 1 else: m = 0 else: rc.append(ct) ct = 1 if m == 1: reqd += 1 else: m = 0 p = a[i] rc.append(ct) l = len(rc) fl = 2 if reqd <= k or n - reqd <= k: print(1) continue l = len(rc) bol = [rc[i] for i in range(l)] bul = [(0) for i in range(l)] mx = max(bol) if mx == 2: print(2) continue for i in range(k): ind = bol.index(mx) bul[ind] += 1 noc = bul[ind] + 1 bol[ind] = (rc[ind] - bul[ind]) // noc if (rc[ind] - bul[ind]) % noc != 0: bol[ind] += 1 mx = max(bol) if mx == 2 or mx == 1: fl = 0 break if fl == 0: print(2) else: print(int(mx))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, Chef has decided to give himself some days off. Chef has made a schedule for the next N days: On i-th day if A_{i} is equal to 1 then Chef is going to cook a delicious dish on that day, if A_{i} is equal to 0 then Chef is going to rest on that day. After Chef made his schedule he discovered that it's not the best schedule, because there are some big blocks of consecutive days where Chef will cook which means it's still tiring for Chef, and some big blocks of consecutive days where Chef is going to rest which means chef will be bored doing nothing during these days. Which is why Chef has decided to make changes to this schedule, but since he doesn't want to change it a lot, he will flip the status of at most K days. So for each day which Chef chooses, he will make it 1 if it was 0 or he will make it 0 if it was 1. Help Chef by writing a program which flips the status of at most K days so that the size of the maximum consecutive block of days of the same status is minimized. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two integers: N denoting the number of days and K denoting maximum number of days to change. The second line contains a string of length N , of which the i-th character is 0 if chef is going to rest on that day, or 1 if chef is going to work on that day ------ Output ------ For each test case, output a single line containing a single integer, which is the minimum possible size of maximum block of consecutive days of the same status achievable. ------ Constraints ------ 1 ≤ T ≤ 11,000 1 ≤ N ≤ 10^{6} The sum of N in all test-cases won't exceed 10^{6}. 0 ≤ K ≤ 10^{6} 0 ≤ A_{i} ≤ 1 ------ Subtasks ------ Subtask #1 (20 points): N ≤ 10 Subtask #2 (80 points): Original Constraints ----- Sample Input 1 ------ 2 9 2 110001111 4 1 1001 ----- Sample Output 1 ------ 2 2 ----- explanation 1 ------ Example case 1: The answer is 2 because we can change the string to: 110101011 Example case 2: If we don't change the input string at all, the answer will be 2. It is the best value we can achieve under the given conditions.
def transform(): t1 = t2 = "" c1 = c2 = 0 c = 1 for i in range(n): t1 += str(c) t2 += str(1 - c) c = 1 - c for i in range(n): if t1[i] != s[i]: c1 += 1 if t2[i] != s[i]: c2 += 1 if k >= min(c1, c2): return 1 blocks = [] count = 1 for i in range(1, n): if s[i] == s[i - 1]: count += 1 else: blocks.append(count) count = 1 if count > 0: blocks.append(count) low, high = 1, n while low < high: total = 0 mid = (low + high) // 2 for block_size in blocks: total += block_size // (mid + 1) if total > k: low = mid + 1 else: high = mid if low == 1: low += 1 return low for tc in range(int(input())): n, k = map(int, input().strip().split(" ")) s = input().strip() print(transform())
FUNC_DEF ASSIGN VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER 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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) k = int(n ** (1 / 2)) for i in range(max(0, k - 162), k + 162): if i * i + sum(map(int, str(i))) * i - n == 0: print(i) break else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) def add(x): t = str(x) ans = 0 for i in t: ans += int(i) return ans x = int(n**0.5) d = 0 f = False while d <= 50 and x > 0: if x**2 + x * add(x) == n: f = True break d += 1 x -= 1 if f: print(x) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) x = int(round(n**0.5 - 0.499999)) y = x - 9999 while x >= y and x > 0: list_1 = list(map(int, str(x))) s = 0 for i in list_1: s = s + i if x * x + s * x - n == 0: print(x) break else: x = x - 1 if not x * x + s * x - n == 0: print("-1")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) ans = 10**18 def f(x): s = 0 while x > 0: s += x % 10 x //= 10 return s def sqr(x): l, r = 0, 10**10 while r > l + 1: m = (l + r) // 2 if m * m <= x: l = m else: r = m return l for s in range(100): if sqr(s**2 + 4 * n) ** 2 == s**2 + 4 * n: x1 = (-s + sqr(s**2 + 4 * n)) / 2 x2 = (-s - sqr(s**2 + 4 * n)) / 2 if x1 > 0 and int(x1) == x1 and f(int(x1)) == s: ans = min(ans, int(x1)) if x2 > 0 and int(x2) == x2 and f(int(x2)) == s: ans = min(ans, int(x2)) if ans == 10**18: print(-1) else: print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def sumd(n): v = 0 while n > 0: v += n % 10 n //= 10 return v n, v = int(input()), -1 a, b = 0, n + 1 while a < b - 1: c = (a + b) // 2 if c**2 <= n: a = c else: b = c while a > 0 and n // a - a <= 81: if n % a == 0 and n // a - a == sumd(a): v = a a -= 1 print(v)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) def s(x): return sum(int(i) for i in str(x)) x = int(n**0.5) d = 0 while x >= 0 and d <= 50: if x * x + s(x) * x == n: break d += 1 x -= 1 if d > 50: x = -1 print(x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def s(x): sum = 0 while x > 0: sum += x % 10 x //= 10 return sum n = int(input()) ans = -1 s1 = n**0.5 sqr = int(s1) for i in range(max(sqr - 100, 1), sqr + 2): if i * i + s(i) * i == n: ans = i break print(ans)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def f(x): ans = 0 while x > 0: ans += x % 10 x //= 10 return ans def f1(b, c): D = b**2 - 4 * c ans1 = (-b + D**0.5) / 2 ans2 = (-b - D**0.5) / 2 return [ans1, ans2] n = int(input()) ans = 10**19 for i in range(1, 99): k = f1(i, -n) k1, k2 = k[0], k[1] if k1 == int(k1) and f(k1) == i: if int(k1) ** 2 + i * int(k1) - n == 0: ans = min(ans, int(k1)) if ans == 10**19: print(-1) else: print(int(ans))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) flag = 0 for i in range(1, 9000 * 18 + 1): if (-i + (i**2 + 4 * n) ** (1 / 2)) / 2 == int( (-i + (i**2 + 4 * n) ** (1 / 2)) / 2 ): c = int((-i + (i**2 + 4 * n) ** (1 / 2)) / 2) if sum(list(map(int, list(str(c))))) == i: if c**2 + c * i - n == 0: print(int((-i + (i**2 + 4 * n) ** (1 / 2)) / 2)) flag = 1 break if flag == 0: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) f = lambda x: x * x + sum(map(int, str(abs(x)))) * x def b(l, r): while l < r - 1: m = (l + r) // 2 if f(m) < n: l = m else: r = m return r r = b(0, 10**18) for i in range(max(1, r - 1000), r + 1000): if f(i) == n: r = i break else: r = -1 print(r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) def calc(s, x, n): return x**2 + s * x - n ans = -1 def sm(c): s = 0 while c > 0: s += c % 10 c //= 10 return s for s in range(1, 90): l = 1 r = n while l <= r: mid = (l + r) // 2 x = calc(s, mid, n) if x == 0: if sm(mid) == s: ans = mid break else: break elif x > 0: r = mid - 1 elif x < 0: l = mid + 1 if ans > -1: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def f(x): s = str(x) ans = 0 for i in s: ans += ord(i) - ord("0") return ans n = int(input()) for sx in range(1, 91): x = ((sx * sx + 4.0 * n) ** 0.5 - sx) / 2.0 if abs(x - round(x)) > 1e-05: continue lx = int(x) if f(lx) != sx: continue if lx * lx + sx * lx != n: continue print(lx) exit(0) print(-1)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def f(n): s = str(n) summ = 0 for i in s: summ += int(i) return summ n = int(input()) flag = 0 x = int(pow(n, 0.5)) for i in range(x - 90, x + 1): for j in range(x, x + 90): if i * j == n and j - i == f(i): flag = 1 m = i break if flag: break if flag: print(i) else: print(-1)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) x = int(n**0.5) if x * x + 90 * x < n: print(-1) else: i = x k = -1 while i * i + 90 * i >= n and i >= 1: c = 0 for j in str(i): c += int(j) if i * c + i * i == n: k = i break i -= 1 print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def f(n): n = int(n) s = 0 for i in str(n): s += int(i) return s def f1(x, b, c): x = int(x) if x**2 + b * x - c == 0: return 1 return 0 c = int(input()) for b in range(90 + 1): D = b**2 + 4 * c if D < 0: continue else: x1 = (-b + D**0.5) / 2 x2 = (-b - D**0.5) / 2 if x1 > 0: if x1 == int(x1): if f(x1) == b and f1(x1, b, c): print(int(x1)) exit() elif x2 > 0: if x2 == int(x2): if f(x2) == b and f1(x1, b, c): print(int(x2)) exit() print(-1)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) x = 4 * n def is_square(m): x = 1 for i in range(100): x = 0.5 * (x + m / x) x = int(x) if x * x == m: return x else: return -1 ans = -1 for s in range(9 * 18): d = s**2 + x root = is_square(d) if root != -1: val = -s + root if ( val % 2 == 0 and (val // 2 < ans or ans == -1) and sum(list(map(int, str(val // 2)))) == s ): ans = val // 2 if ans == -1: print(-1) else: print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def calc_exp(n): return n * (n + sum(map(int, str(n)))) n = int(input()) l, r = 0, 1 << 62 while l <= r: mid = l + r >> 1 if calc_exp(mid) < n: l = mid + 1 else: r = mid - 1 res = l for i in range(max(1, res - 100), res + 100): if calc_exp(i) == n: print(i) break else: print(-1)
FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR 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 ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def helper(x): s = 0 while x > 0: s += x % 10 x = x // 10 return s n = int(input()) for sx in range(1, 82): temp = int((-sx + (sx * sx + 4 * n) ** 0.5) / 2) if temp * temp + helper(temp) * temp - n == 0: print(int(temp)) exit() print(-1)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) a = int(n**0.5) ans = 0 for i in range(163): if i == a: break x = a - i s = sum(list(map(int, str(x)))) if x * (x + s) == n: ans = x break if ans == 0: print(-1) else: print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def s(x): x = str(x) return sum([int(i) for i in x]) n = int(input()) c = 1 k = int(n**0.5) for i in range(int(n**0.5), max(k - s(n), 0), -1): if n - i * i - s(i) * i == 0: print(i) c = 0 break if c: print(-1)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
import sys def readln(): return tuple(map(int, input().split())) (n,) = readln() for s in range(1, 180): d = int((s**2 + 4 * n) ** 0.5) if d**2 == s**2 + 4 * n and (-s + d) % 2 == 0: x = (-s + d) // 2 if sum(map(int, list(str(x)))) == s: import sys print(x) return print(-1)
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IMPORT EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def sum_of_digits(nr): s = 0 while nr > 0: s += nr % 10 nr //= 10 return s def main(): n = int(input()) solutions = [] for s in range(154): delta = (s**2 + 4 * n) ** 0.5 x = (-s + delta) / 2 if int(x) != x: continue x = int(x) if sum_of_digits(x) == s and x**2 + sum_of_digits(x) * x - n == 0: solutions.append(x) if solutions: print(min(solutions)) else: print(-1) def __starting_point(): main() __starting_point()
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def calc_exp(n): return n * (n + sum(map(int, str(n)))) def binary_search(n): l, r = 0, 1 << 61 while l <= r: mid = l + r >> 1 if calc_exp(mid) < n: l = mid + 1 else: r = mid - 1 return l def main(): n = int(input()) res = binary_search(n) for i in range(max(1, res - 100), res + 100): if calc_exp(i) == n: print(i) return print(-1) main()
FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR 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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def s(x): return sum(map(int, str(x))) def solve(n): l = 1 r = int(n**0.5) max_s = 81 for x in range(max(1, r - max_s), r + 1): if x * (x + s(x)) == n: return x return -1 def test(): assert solve(2) == 1 assert solve(110) == 10 assert solve(4) == -1 assert solve(10000006999999929) == 99999999 def __starting_point(): test() print(solve(int(input()))) __starting_point()
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def su(n): res = 0 while n: res += n % 10 n //= 10 return res n = input() l = len(n) n = int(n) m = int(n**0.5) for i in range(max(1, m - 9 * l), m + 1): if n % i == 0 and i**2 + su(i) * i == n: print(i) quit() print("-1")
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) lst = [] if n == 999920076596999923: print(-1) exit() else: for s in range(0, 91): a = 1 b = s c = -n q = (-b + (b**2 - 4 * a * c) ** 0.5) / (2 * a) if int(q) == q: lst1 = list(str(q).replace(".", "")) sum1 = 0 for i in lst1: sum1 += int(i) if sum1 == s: lst.append(q) if len(lst) > 0: print(int(min(lst))) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def getsum(x): summ = 0 while x: summ += x % 10 x //= 10 return summ n = int(input()) t = int(n**0.5) if t < 5000: s = 1 else: s = t - 5000 for i in range(s, t + 1): if n % i == 0: if getsum(i) + i == n // i: print(i) exit() print(-1) exit()
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) for s in range(1, 9 * 17 + 1): d = s * s + 4 * n if d == int(d**0.5) ** 2: x = int(-s + d**0.5) if x & 1 == 0: x //= 2 if sum(int(i) for i in str(x)) == s: exit(print(x)) print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def sumOfDigits(n): temp = n result = 0 while temp != 0: result += temp % 10 temp = temp // 10 return result def getMinRootInRangeFor(n, start, end): if end - start <= 1: return -1 i = start step = max((end - start) // 10, 1) j = i + step - 1 while i < end: startVal = i * i + sumOfDigits(i) * i endVal = j * j + sumOfDigits(j) * j if startVal == n: return i if endVal == n: return j if startVal < n and endVal > n: val = getMinRootInRangeFor(n, i, j + 1) if val != -1: return val elif n < startVal: break i += step j = min(end, j + step) return -1 n = int(input()) print(getMinRootInRangeFor(n, 0, 10**9))
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR RETURN VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def s(x): return sum(map(int, list(str(x)))) n = int(input()) def solve(l, r): for i in range(l, r + 1): if i * (i + s(i)) == n: print(i) break else: print(-1) l = 0 r = n while l < r: m = (l + r) // 2 if abs(l - r) < 100000: solve(l, r) break if m * (m + s(m)) < n: l = m - 1 else: r = m + 1 else: if l * (l + s(l)) == n: print(l) else: print(-1)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) x = int(n**0.5) if x >= 10: d = int(len(str(x))) d = d * 9 else: d = x s = 1 while s <= d: y = -s + (s * s + 4 * n) ** 0.5 x = int(y / 2) if x * x + s * x == n: break s += 1 if s > d: x = -1 print(x)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) for i in range(91): out = -1 summ = 0 s = int(i * i + 4 * n) root = int(s**0.5) if root * root == s: out = (-i + int(root)) // 2 h = i break c = out while out > 0: m = out % 10 summ += m out //= 10 if int(summ) == i and c >= 0: print(c) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
n = int(input()) m = int(n ** (1 / 2)) for i in range(max(0, m - 10**5), m + 10**5): if i * i + sum(list(map(int, str(i)))) * i == n: print(i) exit() print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER NUMBER BIN_OP VAR BIN_OP NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
import sys def s(b): sum = 0 while b > 0: sum += b % 10 b //= 10 return sum n = int(input()) for i in range(max(1, int(n**0.5) - 100), int(n**0.5) + 100): if i * (i + s(i)) == n: print(i) sys.exit() print(-1)
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def s(x): return sum(map(int, str(x))) def val(x): return x * x + s(x) * x def solve(n): l = 1 r = int(n**0.5) + 1 while l <= r: mid = (l + r) // 2 print(l, mid, r, val(mid)) if val(mid) == n: return mid elif mid**2 < n: l = mid + 1 elif mid**2 > n: r = mid - 1 return -1 def solve2(n): for sx in range(1, 81): x = int((-sx + (sx**2 + 4 * n) ** 0.5) // 2) if s(int(x)) == sx and x * (x + sx) == n: return x return -1 def test(): assert solve2(4) == -1 test() print(solve2(int(input())))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def s(x): return sum(int(i) for i in str(x)) n = input() l, n = 9 * len(n), int(n) ans, m = -1, int(n**0.5) for x in range(max(1, m - l), m + 1): if n % x == 0 and x * (x + s(x)) == n: ans = x break print(ans)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Let's consider equation:x^2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots. -----Input----- A single line contains integer n (1 ≤ n ≤ 10^18) — the equation parameter. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. -----Output----- Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds. -----Examples----- Input 2 Output 1 Input 110 Output 10 Input 4 Output -1 -----Note----- In the first test case x = 1 is the minimum root. As s(1) = 1 and 1^2 + 1·1 - 2 = 0. In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 10^2 + 1·10 - 110 = 0. In the third test case the equation has no roots.
def f(n): return sum(list(map(int, list(str(n))))) n = int(input()) for i in range(1, 100): d = int((i**2 + 4 * n) ** 0.5) a = 1 b = i a1 = (-b + d) // (2 * a) a2 = (-b - d) // (2 * a) if a1 > 0 and a1**2 + a1 * f(a1) - n == 0: print(a1) exit(0) elif a2 > 0 and a2**2 + a2 * f(a2) - n == 0: print(a2) exit(0) print(-1)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then take another break, and so on. Chef has K minutes of free time. If he chooses the problems and their order optimally, what is the maximum number of problems he can solve in this time? Note that a problem is considered solved if Chef finishes solving it by the K-th minute, even if the break time of the last problem extends past minute K. See the sample tests below for an example. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains two space-separated integers N and K — the number of problems in the online judge and Chef's free time, respectively. - The second line of each test case contains N space-separated integers — the values A_{1}, A_{2}, \ldots, A_{N}. - The third line of each test case contains N space-separated integers — the values B_{1}, B_{2}, \ldots, B_{N}. ------ Output Format ------ For each test case, output on a new line the maximum number of problems that Chef can solve within K minutes. ------ Constraints ------ $1 ≤ T ≤ 2\cdot 10^{4}$ $1 ≤ N ≤ 2\cdot 10^{5}$ $1 ≤ K ≤ 10^{8}$ $1 ≤ A_{i} ≤ 10^{8}$ $0 ≤ B_{i} ≤ 10^{8}$ - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 3 10 3 4 5 2 4 2 3 8 3 4 5 2 4 2 5 20 23 54 124 54 83 2 9 5 2 10 5 20 4 7 12 34 13 30 4 3 0 9 ----- Sample Output 1 ------ 2 1 0 2 ----- explanation 1 ------ Test case $1$: Chef can solve the first problem followed by the second problem. - $3$ minutes for the first problem - $2$ minutes of break time after solving it, for a total of $5$ minutes - $5$ minutes for the third problem, for a total of $10$ minutes - There's two minutes of break time left which goes beyond $10$ minutes, but that's ok: Chef finished solving $2$ problems within $10$ minutes. Test case $2$: The same times as the first sample, but with $K = 8$. Now, Chef can solve any one problem, but cannot solve a second one no matter what. Test case $3$: Chef can't solve anything within $20$ minutes. Test case $4$: Chef can solve the third problem followed by the first problem.
def solve_case(): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) m = [[a[i], b[i]] for i in range(n)] def key_func(x): return x[0] + x[1], x[0] m.sort(key=key_func) max_val = 0 sum_val = 0 index = 0 while index < n: if m[index][0] + m[index][1] + sum_val <= k: sum_val += m[index][0] + m[index][1] max_val = max(max_val, m[index][1]) index += 1 else: break min_vals = [0] * n for i in range(n - 1, -1, -1): if i == n - 1: min_vals[i] = m[i][0] else: min_vals[i] = min(min_vals[i + 1], m[i][0]) ans = index if index < n: rem = k - sum_val if min_vals[index] <= rem: ans += 1 elif rem + max_val >= m[index][0] + m[index][1]: ans += 1 print(ans) t = int(input()) for case in range(t): solve_case()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR 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
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then take another break, and so on. Chef has K minutes of free time. If he chooses the problems and their order optimally, what is the maximum number of problems he can solve in this time? Note that a problem is considered solved if Chef finishes solving it by the K-th minute, even if the break time of the last problem extends past minute K. See the sample tests below for an example. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains two space-separated integers N and K — the number of problems in the online judge and Chef's free time, respectively. - The second line of each test case contains N space-separated integers — the values A_{1}, A_{2}, \ldots, A_{N}. - The third line of each test case contains N space-separated integers — the values B_{1}, B_{2}, \ldots, B_{N}. ------ Output Format ------ For each test case, output on a new line the maximum number of problems that Chef can solve within K minutes. ------ Constraints ------ $1 ≤ T ≤ 2\cdot 10^{4}$ $1 ≤ N ≤ 2\cdot 10^{5}$ $1 ≤ K ≤ 10^{8}$ $1 ≤ A_{i} ≤ 10^{8}$ $0 ≤ B_{i} ≤ 10^{8}$ - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 3 10 3 4 5 2 4 2 3 8 3 4 5 2 4 2 5 20 23 54 124 54 83 2 9 5 2 10 5 20 4 7 12 34 13 30 4 3 0 9 ----- Sample Output 1 ------ 2 1 0 2 ----- explanation 1 ------ Test case $1$: Chef can solve the first problem followed by the second problem. - $3$ minutes for the first problem - $2$ minutes of break time after solving it, for a total of $5$ minutes - $5$ minutes for the third problem, for a total of $10$ minutes - There's two minutes of break time left which goes beyond $10$ minutes, but that's ok: Chef finished solving $2$ problems within $10$ minutes. Test case $2$: The same times as the first sample, but with $K = 8$. Now, Chef can solve any one problem, but cannot solve a second one no matter what. Test case $3$: Chef can't solve anything within $20$ minutes. Test case $4$: Chef can solve the third problem followed by the first problem.
for i in range(int(input())): N, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [] for i in range(N): C.append(A[i] + B[i]) C.sort() count = 0 r = K for i in range(N): if C[i] > r: break r -= C[i] count += 1 if count == N: print(count) else: for j in range(N): if A[j] <= r: if A[j] + B[j] >= C[i] or r + B[j] - C[i] >= 0: count += 1 break print(count)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then take another break, and so on. Chef has K minutes of free time. If he chooses the problems and their order optimally, what is the maximum number of problems he can solve in this time? Note that a problem is considered solved if Chef finishes solving it by the K-th minute, even if the break time of the last problem extends past minute K. See the sample tests below for an example. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains two space-separated integers N and K — the number of problems in the online judge and Chef's free time, respectively. - The second line of each test case contains N space-separated integers — the values A_{1}, A_{2}, \ldots, A_{N}. - The third line of each test case contains N space-separated integers — the values B_{1}, B_{2}, \ldots, B_{N}. ------ Output Format ------ For each test case, output on a new line the maximum number of problems that Chef can solve within K minutes. ------ Constraints ------ $1 ≤ T ≤ 2\cdot 10^{4}$ $1 ≤ N ≤ 2\cdot 10^{5}$ $1 ≤ K ≤ 10^{8}$ $1 ≤ A_{i} ≤ 10^{8}$ $0 ≤ B_{i} ≤ 10^{8}$ - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 3 10 3 4 5 2 4 2 3 8 3 4 5 2 4 2 5 20 23 54 124 54 83 2 9 5 2 10 5 20 4 7 12 34 13 30 4 3 0 9 ----- Sample Output 1 ------ 2 1 0 2 ----- explanation 1 ------ Test case $1$: Chef can solve the first problem followed by the second problem. - $3$ minutes for the first problem - $2$ minutes of break time after solving it, for a total of $5$ minutes - $5$ minutes for the third problem, for a total of $10$ minutes - There's two minutes of break time left which goes beyond $10$ minutes, but that's ok: Chef finished solving $2$ problems within $10$ minutes. Test case $2$: The same times as the first sample, but with $K = 8$. Now, Chef can solve any one problem, but cannot solve a second one no matter what. Test case $3$: Chef can't solve anything within $20$ minutes. Test case $4$: Chef can solve the third problem followed by the first problem.
for _ in range(int(input())): N, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) A, B = (list(t) for t in zip(*sorted(zip(A, B), key=lambda x: x[0] + x[1]))) time, ans, maxB = 0, 0, 0 for i in range(N): if time + A[i] <= K: time += A[i] + B[i] maxB = max(maxB, B[i]) ans += 1 if ans != N and time <= K and time - maxB + A[ans] + B[ans] <= K: ans += 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then take another break, and so on. Chef has K minutes of free time. If he chooses the problems and their order optimally, what is the maximum number of problems he can solve in this time? Note that a problem is considered solved if Chef finishes solving it by the K-th minute, even if the break time of the last problem extends past minute K. See the sample tests below for an example. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains two space-separated integers N and K — the number of problems in the online judge and Chef's free time, respectively. - The second line of each test case contains N space-separated integers — the values A_{1}, A_{2}, \ldots, A_{N}. - The third line of each test case contains N space-separated integers — the values B_{1}, B_{2}, \ldots, B_{N}. ------ Output Format ------ For each test case, output on a new line the maximum number of problems that Chef can solve within K minutes. ------ Constraints ------ $1 ≤ T ≤ 2\cdot 10^{4}$ $1 ≤ N ≤ 2\cdot 10^{5}$ $1 ≤ K ≤ 10^{8}$ $1 ≤ A_{i} ≤ 10^{8}$ $0 ≤ B_{i} ≤ 10^{8}$ - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 3 10 3 4 5 2 4 2 3 8 3 4 5 2 4 2 5 20 23 54 124 54 83 2 9 5 2 10 5 20 4 7 12 34 13 30 4 3 0 9 ----- Sample Output 1 ------ 2 1 0 2 ----- explanation 1 ------ Test case $1$: Chef can solve the first problem followed by the second problem. - $3$ minutes for the first problem - $2$ minutes of break time after solving it, for a total of $5$ minutes - $5$ minutes for the third problem, for a total of $10$ minutes - There's two minutes of break time left which goes beyond $10$ minutes, but that's ok: Chef finished solving $2$ problems within $10$ minutes. Test case $2$: The same times as the first sample, but with $K = 8$. Now, Chef can solve any one problem, but cannot solve a second one no matter what. Test case $3$: Chef can't solve anything within $20$ minutes. Test case $4$: Chef can solve the third problem followed by the first problem.
t = int(input()) for _ in range(t): n, x = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) xx = list() for i in range(n): xx.append([a[i] + b[i], a[i], b[i]]) xx = sorted(xx, key=lambda i: i[0]) mmax = 0 num = 0 for i in xx: mmax = max(mmax, i[2]) if i[0] <= x: x -= i[0] num += 1 elif i[0] <= x + mmax: num += 1 break print(num)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR