description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
import sys for _ in range(int(sys.stdin.readline().rstrip())): n = int(sys.stdin.readline().rstrip()) t = "{0:b}".format(n) re = 0 tlen = len(t) for i in range(tlen): if t[i] == "1": re += 2 ** (tlen - i) - 1 print(re)
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
def pow(x): a = 0 b, c = 1, 0 while x >= 1: b *= 2 a += 1 if b > x: a -= 1 return a for _ in range(int(input())): n = int(input()) i1, i2 = 0, 0 x = n while x >= 1: a = pow(x) x -= 2**a i1 += 2**a * 2 - 1 print(i1)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NU...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
def _sum2(n): return 2 * n - bin(n).count("1") t = int(input()) for i in range(t): n = int(input()) print(_sum2(n))
FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
import sys def main(): import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline T = int(input()) for t in range(T): n = int(input()) p = 1 ans = 0 while p <= n: ans += n // p p *= 2 print(ans) main()
IMPORT FUNC_DEF IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
import sys input = sys.stdin.readline def main(): t = int(input()) def f(k): pw = 2 s = 0 while True: s += k // pw * (pw // 2) s += max(0, k % pw - pw // 2) if k < pw: break pw *= 2 return s for _ in range(t...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
for i in range(int(input())): n1 = int(input()) bit = 0 n = n1 l = [] while n > 0: l.append(n % 2) n = n // 2 bit += 1 ans = 0 b = 0 for i in range(bit): if l[i] == 1: b += 1 ans += 2 ** (i + 1) print(ans - b)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMB...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) for _ in range(t): n = int(input()) p2, add = 1, 1 ans = 0 while p2 <= n: ans += (1 + (n - p2) // (2 * p2)) * add p2 *= 2 add += 1 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 VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
def bitsoncount(x): return bin(x).count("1") t = int(input()) while t: n = int(input()) print(2 * n - bitsoncount(2 * n)) t -= 1
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) for _ in range(t): n = int(input()) ans = 0 i = 1 c = n while n > 0: if n % 2 == 0: x = n // 2 else: x = n // 2 + 1 ans += i * x n = n - x i += 1 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
xor = [(0) for _ in range(61)] xor[0] = 1 for i in range(1, 61): xor[i] = xor[i - 1] * 2 + 1 for _ in range(int(input())): n = int(input()) bi = bin(n)[2:] bi = bi[::-1] n = len(bi) summ = 0 for j in range(1, n + 1): if bi[j - 1] == "1": summ += xor[j - 1] print(summ)
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSI...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
testy = int(input()) results = [] liczby = [] liczby.append(0) liczby.append(1) summ = 1 for i in range(2, 61): liczby.append(2 * summ + 1) summ = liczby[i] for i in range(testy): n = int(input()) res = 0 x = bin(n) y = x[2 : len(x) + 1] for j in range(len(y)): if y[j] == "1": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN V...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input("")) num = [] for i in range(t): num.append(int(input(""))) for i in num: sol = 0 while i > 0: sol += i i = i // 2 print(sol)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = 1 t = int(input()) for _ in range(t): n = int(input()) + 1 ans = 0 k = 0 for i in range(len(bin(n)[2:])): factor = 2**k ans += n // factor - 1 k += 1 if n % factor != 0: ans += 1 print(ans)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR ...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
def sol(n): if n == 1 or n == 0: return n i = 1 while i <= n: i *= 2 return i - 1 + sol(n - i // 2) for _ in range(int(input())): n = int(input()) print(sol(n))
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
dp = [0] * 61 for i in range(1, 61): dp[i] = dp[i - 1] for j in range(0, i - 1): dp[i] += dp[j] dp[i] += i t = int(input()) for i in range(t): n = int(input()) cnt = 1 ans = 0 while n: if n % 2: ans += dp[cnt] n = n // 2 cnt += 1 print(ans)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR 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 NUMBER ASSIGN VAR NU...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
import sys try: t = int(input()) for _ in range(t): n = int(input()) x = n s = 0 n = bin(n) n = n.lstrip("0b") p = 1 for i in range(len(n)): s += x // p p *= 2 print(s) except EOFError: pass
IMPORT 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
lst = [] for j in range(62): if j == 0: lst.append(1) else: total = 0 for k in range(j): total += lst[k] total += j + 1 lst.append(total) t = int(input()) for i in range(t): n = "{:b}".format(int(input())) n = n[::-1] tot = 0 for p in range(len...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VA...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) while t != 0: t -= 1 n = int(input()) p = bin(n) s = len(p) - 2 ans = 0 for i in range(s): ans += n // 2**i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
dp = [1] for i in range(66): x = dp[i] * 2 + 1 dp.append(x) t = int(input()) for _ in range(t): n = int(input()) n = str(bin(n)[2:])[::-1] j = 0 ans = 0 for i in n: if i == "1": ans += dp[j] j += 1 print(ans)
ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR 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 FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER F...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
for i in range(int(input())): n = int(input()) c = 0 for i in range(64): if n >> i & 1 != 0 >> i & 1: c = c + 1 print(2 * n - c)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
T = int(input()) D = [] for i in range(0, T): n = int(input()) s = 0 k = 0 a = n while a >= 1: s += a k += 1 a = n // 2**k D.append(s) for i in D: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
from sys import stdin, stdout int_in = lambda: int(stdin.readline()) arr_in = lambda: [int(x) for x in stdin.readline().split()] mat_in = lambda rows: [arr_in() for y in range(rows)] str_in = lambda: stdin.readline().strip() out = lambda o: stdout.write("{}\n".format(o)) arr_out = lambda o: out(" ".join(map(str, o))) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STR...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
for _ in " " * int(input()): a = int(input()) ans = 0 for i in range(0, 62): if a & 1 << i: ans += 2 * 2**i - 1 print(ans)
FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
def fiasco(n): r = bit(n) result = 0 for i in range(len(r)): if r[i] == 1: result += 2 ** (len(r) - i) - 1 return result def bit(n): s = [] while n != 0 and n != 1: s.append(n % 2) n = n // 2 s.append(n) s.reverse() return s for i in range(int(...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL ...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) while t != 0: n = int(input()) bitPosition = 1 result = 0 while n > 0: if n & 1 == 1: result += 2**bitPosition - 1 bitPosition += 1 n = n >> 1 print(result) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
d = {} d[0] = 1 for i in range(1, 61): d[i] = d[i - 1] * 2 for i in range(int(input())): n = int(input()) ans = n count = 1 while d[count] <= n: ans += n // 2**count count += 1 print(ans)
ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUN...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) while t >= 1: n = int(input()) s = 1 cnt = int(0) while 1: cnt += n // s if n // s == 0: break s = s * 2 t = t - 1 print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE NUMBER VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
for t in range(int(input())): n = int(input()) b = n ans = 0 while n > 1: x = len(bin(n).replace("0b", "")) - 1 ans += 2 ** (x + 1) - 1 n = n - 2**x if n == 1: print(ans + 1) else: print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUM...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) for _ in range(t): n = int(input()) n += 1 res = 0 for i in range(60, -1, -1): temp = 1 << i if temp <= n: temp1 = n // temp if n % temp != 0: temp1 += 1 res += temp1 - 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR V...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
def decimalToBinary(n): return bin(n).replace("0b", "") for _ in range(int(input())): n = int(input()) print(n * 2 - decimalToBinary(n).count("1"))
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR STRING
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
def countSetBits(n): if n == 0: return 0 else: return 1 + countSetBits(n & n - 1) for _ in range(int(input())): n = int(input()) print(2 * n - countSetBits(n))
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
mylist = [0] * 61 mylist[1] = 1 mylist[2] = 3 for i in range(3, 61): mylist[i] = 2 * mylist[i - 1] + 1 cases = int(input()) for i in range(cases): n = int(input()) ans = 0 while n > 0: ans += n n //= 2 print(ans)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER 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 WHILE VAR ...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) for _ in range(t): n = int(input()) a = bin(n) a = a[2:] l = a.count("1") print(2 * n - l)
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 ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
l = [] l.append(0) for i in range(60): l.append(l[-1] + 2**i) for _ in range(int(input())): n = int(input()) ans = 0 x = bin(n)[2:] x = x[::-1] for i in range(len(x)): if x[i] == "1": ans += l[i + 1] print(ans)
ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CA...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
for _ in range(int(input())): k = int(input()) r = 0 i = x = 1 while x: x = -(-(1 + k - int(2 ** (i - 1))) // 2**i) r += x * i if x == 0: break i += 1 print(r)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
import sys IN = [x.strip() for x in sys.stdin.readlines()] T = int(IN[0]) vals = [] for i in range(T): vals.append(bin(int(IN[1 + i]))[2:]) nb = max([len(v) for v in vals]) bit2count = [(2**i - 1) for i in range(1, nb + 1)] for n in vals: n = n l = len(n) tot = 0 for i in range(l): tot += b...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMB...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
import sys def main(): for t in range(int(input())): n = int(input()) s = bin(n)[2:] print(2 * n - s.count("1")) main()
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) def f(n): cnt = 0 while n: cnt += n n //= 2 return cnt for _ in range(t): n = int(input()) print(f(n))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
import sys input = sys.stdin.readline for _ in range(int(input())): N = int(input()) bn = list(bin(N))[2:] bn.reverse() res = 0 for i in range(len(bn)): res += (bn[i] == "1") * (pow(2, i + 1) - 1) print(res)
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXP...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
import sys lines = [] for line in sys.stdin: if "Exit" == line.rstrip(): break lines.append(line) t = int(lines[0]) cumsum = [0] hi = 0 for j in range(1, t + 1): n = int(lines[j]) s = "{0:064b}".format(n) counter = s.count("1") print(n * 2 - counter)
IMPORT ASSIGN VAR LIST FOR VAR VAR IF STRING FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VA...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
for t in range(int(input())): n = int(input()) su = n // 2 + (n % 2 == 1) i = 2 d = 2 while i <= n: su += (n // i - n // (i * 2)) * d d += 1 i = i * 2 print(su)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) for _ in range(t): n = int(input()) a = [0] while n != 0: a.append(n % 2) n = n // 2 k = len(a) s = [0] * 64 s[1] = 1 s[2] = 4 res = 0 for i in range(3, len(a)): s[i] = s[i - 1] + i + s[i - 1] for i in range(len(a) - 1, 0, -1): if ...
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 EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER N...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
t = int(input()) for i in range(t): number = int(input()) count_of_iter = len(bin(number)) - 2 ans = 0 for j in range(0, count_of_iter): ans += (j + 1) * ((number + 2**j) // 2 ** (j + 1)) 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 BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_C...
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills. The boy is now looking at the ratings of consecutive participan...
import sys def input(): return sys.stdin.readline().rstrip("\r\n") def List(): return list(map(int, input().split())) def Num(): return int(input()) def solve(): n = Num() return 2 * n - bin(n).count("1") for _ in range(Num()): print(solve())
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN BIN_OP BIN_OP NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CAL...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
bits = 0 n, k = map(int, input().split()) maxbits = 0 a = [] for bit in range(0, 30): if n & 1 << bit: bits += 1 maxbits += 2**bit a.append(1) else: a.append(0) if bits > k or maxbits < k: print("NO") exit() a = a[::-1] for i in range(29): if a[i] == 0: contin...
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CAL...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) def binary(n): l = [] while n > 0: l.append(n % 2) n = n // 2 return l s = 0 t = 0 l = binary(n) for i in range(len(l)): if l[i]: s += 2**i t += 1 if s >= k and t <= k: print("YES") i = len(l) - 1 while t != k: if t...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR NU...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
import gc def main(): n, k = list(map(int, input().split())) if n < k: print("NO") return if n == k: print("YES") print(" ".join(["1"] * k)) return powers = [] while n: x = 1 while x * 2 <= n: x *= 2 n -= x powers....
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP LIST STRING VAR RETURN ASSIGN VAR LIST WHILE VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def bincalc(n): s = [] v = 0 while n: r = n % 2 s.append(r) n //= 2 v += r return s[::-1], v n, k = list(map(int, input().split())) a, v = bincalc(n) if v > k or k > n: print("NO") else: print("YES") c = v i = 0 while c < k: if a[i] > 0: ...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR RETURN VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) b = bin(n)[2:][::-1] ar = [] for i in range(len(b)): if int(b[i]): ar.append(2**i) if n < k or len(ar) > k: print("NO") else: for i in range(30): ar.sort(reverse=True) ct = k - len(ar) for i in range(len(ar)): mult = 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def split(power, terms): if terms == 0: return [] if terms == 1: return [2**power] left = terms // 2 right = terms - left return split(power - 1, left) + split(power - 1, right) def main(n, k): bits_n = "{0:b}".format(n) count = sum(1 for bit in bits_n if bit == "1") if...
FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER RETURN LIST BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING IF VAR V...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split(" ")) answer = [(1) for i in range(0, k)] total_sum = k for i in range(0, k): while total_sum + answer[i] <= n: total_sum = total_sum + answer[i] answer[i] = answer[i] * 2 if total_sum != n: print("NO") else: print("YES") for n in answer: print(n, en...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR WHILE BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FO...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
t, k = map(int, input().split()) s = str(bin(t))[2:] if t < k or k < s.count("1"): print("NO") else: l = [int(i) for i in s] l.reverse() for i in range(len(l) - 1, 0, -1): if l[i] != 0: if sum(l) + l[i] < k: l[i - 1] += 2 * l[i] l[i] = 0 el...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF BIN_OP...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) s = bin(n)[2:] s = list(s) c = 0 for i in range(len(s)): s[i] = int(s[i]) if s[i] == 1: c += 1 if c == k: s.reverse() ans = [] i = 0 p = 1 while i < len(s): while s[i] > 0: ans.append(p) s[i] -= 1 i += 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
import sys n, m = map(int, input().split()) if m > n: print("NO") sys.exit(0) l = 1 ct = 0 dic = {} while n > 0: if n % 2: dic[l] = 1 ct += 1 else: dic[l] = 0 n //= 2 l *= 2 if m < ct: print("NO") else: print("YES") q = l l //= 2 while ct != m: ...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split(" ")) a = [] while n > 0: i = 1 while i * 2 <= n: i *= 2 n -= i a.append(i) if len(a) > k: print("NO") exit() k -= len(a) i = 0 while k > 0 and i < len(a): while a[i] > 1 and k > 0: a.append(a[i] // 2) a[i] = a[i] // 2 k -= 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def countSetBits(n): count = 0 while n: count += n & 1 n >>= 1 return count n, k = list(map(int, input().split())) jj = countSetBits(n) bi = bin(n)[2:] a = [] l = len(bi) for i, j in enumerate(bi): if j == "1": a.append(2 ** (l - 1 - i)) kk = 0 if k < jj or k > n: print("NO...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def main(): n, k = list(map(int, input().split(" "))) binary = list(map(int, "{0:0b}".format(n))) bin_sum = sum(binary) if k > n or bin_sum > k: print("NO") else: print("YES") i = 0 dif = k - bin_sum while dif: if binary[i] <= dif: ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR IF VAR VAR VAR ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) final = [1] * k kCopy = k for i in range(k): while kCopy + final[i] <= n: kCopy += final[i] final[i] *= 2 if sum(final) == n: print("YES") print(*final) else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) binn = [int(i) for i in bin(n)[2:]] if n >= k >= binn.count(1): print("YES") b = [pow(2, i) for i, j in enumerate(binn[::-1]) if j] i = 0 while len(b) < k: while b[i] > 1 and len(b) < k: x = b[i] // 2 b[i] = x b.append(x) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR WHILE VAR VAR NUMBER FUNC_CA...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = (int(i) for i in input().split()) p = 0 nD = n d_arr = [] while nD > 0: if nD % 2 == 1: d_arr.append(2**p) nD = nD // 2 p += 1 flag = False ones = 0 for i in d_arr: if i == 1: ones += 1 else: break while not flag: if len(d_arr) == k: print("YES") pr...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER WHILE VAR IF FU...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) b = format(n, "b") one = b.count("1") if k < one or k > n: print("NO") exit() print("YES") b = list(map(int, list(b))) for _ in range(k - one): for i in range(len(b) - 1): if b[i] >= 1: b[i] -= 1 b[i + 1] += 2 break b.reverse() ans...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def dec_to_bin(n): bin = [] while n != 0: bin.append(n % 2) n = n // 2 return bin n, k = map(int, input().split()) bin = dec_to_bin(n) su = sum(bin) if su > k or k > n: print("NO") else: pos = len(bin) - 1 while True: if su - bin[pos] + 2 * bin[pos] < k: bin...
FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBE...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split(" ")) power1 = [int(0)] * k a1 = k - 1 ans = 0 for i in power1: ans += 2**i def program(power, a): global n, ans if a < 0: print("NO") return 0 if ans == n: print("YES") for i in power1: print(2**i, end=" ") return None ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def count(a): result = 0 while a != 0: if a % 2 == 1: result += 1 a //= 2 return result n, k = map(int, input().split()) if count(n) > k or k > n: print("NO") exit(0) components = [] a = n while a != 0: components.append(a % 2) a //= 2 for i in range(len(compone...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def my_range(start, end, other_condi): while start < end and other_condi: yield start start += 1 n, k = map(int, input().split()) ans = [1] * k n -= k for i in my_range(0, k, n): while ans[i] <= n: n -= ans[i] ans[i] <<= 1 i += 1 if n == 0: print("YES") print(*ans) ...
FUNC_DEF WHILE VAR VAR VAR EXPR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) a = list(eval(i) for i in str(bin(n))[2:]) l = a.count(1) end = [] if l > k: print("NO") quit() while l < k: if len(a) == 1: print("NO") quit() a[0] = a[0] - 1 a[1] = a[1] + 2 l += 1 if a[0] == 0: a = a[1:] else: l = len(a) for...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
pt = [(2**x) for x in range(31)] def min_powers_of_two(n, l=[]): for i in range(31): if pt[i] == n: l.append(pt[i]) return l elif pt[i] > n: l.append(pt[i - 1]) return min_powers_of_two(n - pt[i - 1], l) def k_powers_of_two(k, l, lsize): d = k ...
ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def fun(a, n): p = [] if n == 1: return [a] if a == n: p.extend([(1) for i in range(a)]) return p manager = n - 1 p = [a] while manager > 0: q = p.pop() p.extend([int(q / 2), int(q / 2)]) manager = manager - 1 if manager >= int(q / 2): ...
FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER RETURN LIST VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_O...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def max_2_pow(n): k = 0 while n > 0: n = n // 2 k += 1 return 2 ** (k - 1) n, k = [int(x) for x in input().split(" ")] l = [] if k <= n: if n % 2 != 0: l.append(1) k -= 1 n -= 1 while n > 0 and k > 0: p = max_2_pow(n) l.append(p) n -=...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST IF VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBE...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) b = format(n, "b") a = [] for i in b: a.append(int(i)) l = 0 if n >= k and k >= sum(a): print("YES") while sum(a) != k: a[l] -= 1 a[l + 1] += 2 if a[l] == 0: l += 1 x = "" for i in range(len(a)): for j in range(a[i]): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING WHILE FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NU...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) arr = [1] * k n -= k i = 0 while i < k and n: while arr[i] <= n: n -= arr[i] arr[i] *= 2 i += 1 if n: print("NO") else: print("YES", *arr)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) A = [] for i in range(30, -1, -1): if n >= 1 << i: n -= 1 << i A.append(1 << i) for i in range(k): while len(A) < k and i < len(A) and A[i] > 1: A.append(A[i] // 2) A[i] //= 2 if len(A) != k: print("NO") else: print("YES") print(*A)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = [int(i) for i in input().split()] str = bin(n)[2:] l = [int(i) for i in list(str[::-1])] p = [] for i in range(30): p.append(2**i) if str.count("1") > k: print("NO") elif k > n: print("NO") else: length = len(l) for x in range(k - str.count("1")): for i in range(1, length): ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = list(map(int, input().split())) bin_n = bin(n)[2:] a = [] for i in bin_n: a.append(int(i)) l = len(a) s = sum(a) if s > k: print("NO") exit() if s == k: print("YES") for i in range(l): for j in range(a[i]): print(2 ** (l - i - 1), end=" ") exit() for i in range(l - 1):...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRI...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = input().split(" ") n = int(n) k = int(k) a = [] temp = 1 while temp <= n: a.append(temp) temp = temp * 2 if k == 1: found = 0 for i in a: if n == i: found = 1 break if found: print("YES") print(n) else: print("NO") elif k > n: pr...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def mi(): return map(int, input().split(" ")) n, k = mi() s = bin(n)[2:] ub = 0 for i in s: if int(i) == 1: ub += 1 powers = [] i = 1 while i < 10000000000.0 + 7: powers.append(i) i *= 2 ans = [1] * k if n < k or k < ub: print("NO") else: print("YES") if sum(ans) == n: prin...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def binary(n, a): if n > 1: binary(n // 2, a) a.append(n % 2) n, k = map(int, input().split()) a = [] binary(n, a) m1 = 0 m2 = 0 a = a[::-1] ans = [] m3 = 0 for i in range(len(a)): if a[i] == 1: m1 += 1 m2 += 2**i ans.append(2**i) m3 += 1 if k >= m1 and k <= n: ...
FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
import sys input = sys.stdin.readline n, k = map(int, input().split()) if n < k or bin(n)[1:].count("1") > k: print("NO") else: print("YES") s = k ans = [1] * k for i in range(k): while s + ans[i] <= n: s += ans[i] ans[i] *= 2 print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER E...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def base2(n): n = int(n) res = "" while n > 0: res += str(n % 2) n = n // 2 return res[::-1] t, k = input().split() n = str(base2(t)) if int(t) < int(k) or int(k) < n.count("1"): print("NO") else: k = int(k) lis = [] for i in range(len(n)): lis.append(int(n[i]))...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
entrada = input().split() n = int(entrada[0]) k = int(entrada[1]) arr_result = [] k_temp = k n_temp = n soma = 0 m = 0 i = 30 while i >= 0 and k >= 0: m = 1 << i if m > n or n - m < k - 1: i -= 1 continue soma += m arr_result.append(m) n -= m k -= 1 if len(arr_result) == k_temp a...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER V...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
N = [int(i) for i in input().split()] kol = N[1] number = N[0] k = 1 arr = [] flag = 1 if kol > number: flag = 0 elif kol == number: flag = 2 else: while number != 0: while k <= number: k *= 2 k /= 2 number -= k arr.append(int(k)) k = 1 our_kol = len(a...
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def main(): arr = input().split() total = int(arr[0]) count = int(arr[1]) store = [] test = 1 while test <= total: if test & total: store.append(test) test *= 2 if len(store) > count: print("NO") else: position = 0 while len(store) != c...
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF BIN_...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = [int(x) for x in input().split()] ans = [] power = [] for i in range(0, 34): power.append(2**i) flag = 0 temp = 0 m = n prev = temp while True: temp = 0 k -= 1 for i in power: temp = i if m - temp < k: temp = prev break prev = temp m -= temp ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR V...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = input().split(" ") n = int(n) k = int(k) s = format(n, "b") s = list(s) s = map(int, s) s = list(s) s = s[::-1] m = sum(s) if k == m: print("YES") i = 0 while i < len(s): if s[i]: print(2**i, end=" ") i += 1 print() elif k == n: print("YES") print("1 " * k) ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING A...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) if k > n: print("NO") else: count = 0 l = bin(n) b = l[2:] my = [] length = len(b) for i in range(length): num = int(b[i]) * 2 ** (length - 1 - i) if num != 0: my.append(num) count += 1 if k < count: print("...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def main(): n, k = map(int, input().split()) n = bin(n)[2:] n = [int(x) for x in n] vetor = [] soma = 0 for d in n: vetor.append(d) soma += d p = 0 while p < len(n) - 1 and soma < k: if vetor[p] > 0: vetor[p] -= 1 vetor[p + 1] += 2 ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = list(map(int, input().split())) bin_array = list(map(int, bin(n)[:1:-1])) while len(bin_array) > 1 and sum(bin_array) < k: bin_array[-2] += 2 bin_array[-1] -= 1 if bin_array[-1] == 0: bin_array.pop() if sum(bin_array) != k: print("NO") exit() print("YES") print(" ".join(str(2**i) for ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR S...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
input = __import__("sys").stdin.readline lis = [0] * 32 lis[0] = 1 for i in range(1, 32): lis[i] = 2 * lis[i - 1] n, k = map(int, input().split()) ans = [1] * k if n < k: print("NO") else: n -= k for i in range(k): n += 1 c = 0 for j in range(31, -1, -1): if lis[j] <=...
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING VAR VAR FOR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) A = [] PoT = [] for i in range(35): temp = 2**i if n >= temp: A.append(0) PoT.append(2**i) lenPoT = len(PoT) temp_k = 0 temp_n = n IsMAX = True for i in range(1, lenPoT + 1): temp_PoT = PoT[lenPoT - i] while temp_n >= temp_PoT: temp_n -= temp_PoT ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL V...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = [int(_) for _ in input().split()] b = [int(_) for _ in bin(n)[2:]] c = b.count(1) b.reverse() z = [] for i in range(len(b)): if b[i] == 1: z.append(2**i) count = 0 ans = "" if k == c: print("YES\n" + " ".join([str(_) for _ in z])) elif k < c or k > n: print("NO") else: while len(z) + coun...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR STRING IF ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
N, k = list(map(int, input().split())) n = N mas = [1] * 32 ans = [0] * 32 for i in range(1, 32): mas[i] = mas[i - 1] * 2 I = 31 while n > 0: if n >= mas[I]: ans[I] += 1 n -= mas[I] I -= 1 if sum(ans) > k or k > N: print("NO") else: print("YES") k -= sum(ans) while k > 0: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) if k > n: print("NO") else: a = [ 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = list(map(int, input().split())) potenciasde2 = [] pot2 = 1 while pot2 <= n: if pot2 & n: potenciasde2.append(pot2) pot2 *= 2 if len(potenciasde2) > k or k > n: print("NO") else: print("YES") while k != len(potenciasde2): i = potenciasde2.index(max(potenciasde2)) maximo...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL V...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def GETBIT(x, bit): return x >> bit & 1 def solve(n, k): if n < k: print("NO") return sbit = 0 lst = [0] * k for i in range(30): if GETBIT(n, i) == 1: sbit += 1 if sbit <= k: lst[sbit - 1] = i if sbit > k: print("NO") ...
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) n = bin(n) n = n[2:] l = len(n) - 1 Ans = "" i = l comb = [] while i >= 0: if n[i] != "0": comb.append(2 ** (l - i)) i -= 1 if len(comb) < k: i = len(comb) - 1 while i >= 0 and len(comb) < k: if comb[i] // 2 != 0: num = comb.pop(i) // 2 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR A...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) a = [1] * k if n == k: print("YES") print(*a) else: sum = k i = k - 1 while i >= 0: while sum + a[i] <= n: sum += a[i] a[i] *= 2 i -= 1 if sum >= n: break if sum != n: print("NO") exit() ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR ...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
i = 0 b = [] while 2**i < 10**9: b.append(2**i) i += 1 ans = [] n, k = map(int, input().split()) temp = n for i in reversed(b): while k > 0 and n - i >= k - 1: ans.append(i) k -= 1 n -= i if sum(ans) != temp: print("NO") else: print("YES") print(*ans)
ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NU...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
nk = input().split() n = int(nk[0]) k = int(nk[1]) n_bin = [] n_cop = n i = 0 while n_cop > 0: if n_cop % int(2 ** (i + 1)) != 0: n_bin.append(1) n_cop -= int(2**i) else: n_bin.append(0) i += 1 if k < sum(n_bin) or k > n: print("NO") else: print("YES") sum_n_bin = sum(n_b...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
n, k = map(int, input().split()) s = [] while n: s.append(n & -n) n &= n - 1 ones = list(filter(lambda x: x == 1, s)) rem = list(filter(lambda x: x > 1, s)) def split(): if len(rem) == 0: print("NO") exit(0) x = rem.pop() if x == 2: ones.append(1) ones.append(1) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_...
A positive integer x is called a power of two if it can be represented as x = 2^y, where y is a non-negative integer. So, the powers of two are 1, 2, 4, 8, 16, .... You are given two positive integers n and k. Your task is to represent n as the sum of exactly k powers of two. Input The only line of the input contain...
def func(n, k): total = k arr = [(1) for i in range(k)] i = k - 1 while i >= 0: while total + arr[i] <= n: total += arr[i] arr[i] *= 2 i -= 1 if total != n: print("NO") else: print("YES") for i in range(0, k, 1): print(a...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN...