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 drawin...
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...
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 drawin...
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(...
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 ...
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 drawin...
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 ...
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 ...
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 drawin...
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 STRIN...
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 drawin...
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)) ...
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_CAL...
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 drawin...
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(*...
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...
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 drawin...
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 ...
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...
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 drawin...
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 EXP...
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 drawin...
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 ran...
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 ...
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 drawin...
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)...
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...
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 drawin...
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: ...
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...
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 drawin...
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 F...
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 drawin...
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_C...
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 drawin...
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 ...
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 drawin...
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 VA...
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 drawin...
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...
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 AS...
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 drawin...
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 F...
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 drawin...
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)) ...
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 EXP...
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 drawin...
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: ...
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 ...
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 drawin...
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_CA...
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 drawin...
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 ...
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 drawin...
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_CA...
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 drawin...
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(ri...
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 ASSIG...
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 drawin...
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 -= ...
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...
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 drawin...
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): ...
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 V...
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 drawin...
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()) ...
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_...
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 drawin...
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 VA...
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 drawin...
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 = [] ...
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...
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 drawin...
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()) ...
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...
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 drawin...
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) ...
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_C...
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 drawin...
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 ...
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 drawin...
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 FUN...
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 drawin...
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 ...
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 V...
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 drawin...
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: ...
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 V...
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 drawin...
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_CA...
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 drawin...
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 = lis...
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 BI...
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 drawin...
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 ...
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...
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 drawin...
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 ...
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 VA...
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 drawin...
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 ...
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 I...
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 drawin...
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 drawin...
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 E...
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 drawin...
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, -...
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 F...
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 s...
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_contiguou...
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 V...
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 s...
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: ...
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 ...
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 s...
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) ...
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_CAL...
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 s...
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]: ...
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 N...
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 s...
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 ...
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_O...
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 s...
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):...
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 NUMBE...
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 s...
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(i...
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 FUN...
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 s...
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 ...
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 BI...
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 s...
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]: strea...
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...
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 s...
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]: ...
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 NUMBE...
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 s...
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 ...
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 ...
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 s...
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: ...
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 NUMBE...
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 s...
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) ...
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 V...
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 s...
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 +...
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...
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 s...
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]...
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 V...
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 s...
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 ...
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 NU...
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 s...
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 = [] ...
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 ...
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--...
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...
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--...
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 N...
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--...
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 ...
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--...
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(...
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 ASSI...
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--...
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 ...
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 BI...
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--...
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_...
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--...
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_C...
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--...
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 =...
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 AS...
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--...
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: ...
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 NUMB...
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--...
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 br...
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 NUMBE...
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--...
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 s...
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 ...
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--...
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...
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 VA...
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--...
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: ...
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 ...
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--...
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 BI...
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--...
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 ...
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 NUM...
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--...
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...
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 V...
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--...
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 el...
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 VA...
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--...
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...
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--...
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 VA...
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--...
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...
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--...
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) ...
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 NUMBE...
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--...
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) ...
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...
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--...
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) ...
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 VA...
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--...
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...
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...
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--...
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 NUMBE...
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--...
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 ...
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...
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--...
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...
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--...
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 FUN...
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--...
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: ...
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...
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--...
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) ...
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 ASSIG...
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--...
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...
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--...
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: ...
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 WH...
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--...
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_CAL...
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--...
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...
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--...
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 ...
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 ...
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--...
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_O...
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--...
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 + ...
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...
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 t...
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 <...
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_...
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 t...
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 ...
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...
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 t...
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: ...
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 ...
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 t...
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: ...
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_CAL...