description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1:
print((n - 1) * a)
quit()
ans = 0
while n > 1:
if n < k:
ans += (n - 1) * a
n = 1
continue
ans += min(n % k * a + b, (n - (n - n % k) // k) * a)
n -= n % k
n //= k
print(int(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSI... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
x = n
s = 0
while x > 1:
if x % k != 0 and x > k:
s = s + A * (x % k)
x = x - x % k
elif x >= k:
if x * (k - 1) // k * A > B:
x = x // k
s = s + B
else:
s = s + A * (x - 1)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | def solve(n, k, a, b):
ans = 0
if k == 1:
print((n - 1) * a)
return
while n != 1:
if n < k:
ans += (n - 1) * a
n = 1
elif n % k != 0:
ans += n % k * a
n -= n % k
elif b < (n - n // k) * a:
n /= k
... | FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
cost = 0
if k == 1:
print(A * (n - 1))
else:
while n != 1:
if n % k != 0:
shift = n % k if n > k else n - 1
tcost = shift * A
n -= shift
else:
tcost = min(B, A * (n - n // k))
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
total = 0
flag = True
while n > 1:
if n < k:
total += (n - 1) * A
break
if n % k == 0:
new = n / k
if flag:
if B <= A * (n - new):
total += B
n = new
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR IF VAR BI... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | import sys
def read_int():
return int(input())
def read_ints():
return [int(x) for x in input().split()]
n = read_int()
k = read_int()
a = read_int()
b = read_int()
cost = 0
if k == 1:
cost = (n - 1) * a
else:
while n != 1:
if n % k == 0:
if b < (n - n // k) * a:
... | IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, A, B = [int(input()) for i in "iiii"]
s = 0
if k != 1:
while n != 1 and n > 0:
if n % k == 0:
n = n // k
s += min(n * (k - 1) * A, B)
else:
s += n % k * A
n = n - n % k
if n == 0:
s -= A
n = 1
print... | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
if k == 1:
print(A * (n - 1))
else:
ans = 0
while n != 1:
if n >= k:
ans += n % k * A
n -= n % k
else:
ans += (n - 1) * A
break
while n != 1 and n % k == 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
s = 0
while n != 1:
if k == 1:
s = (n - 1) * a
break
if n >= k:
if n % k == 0:
if b < a * (n - n // k):
n = n // k
s += b
else:
s += a * (n - n // k... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
c = 0
while n != 1:
if n % k == 0 and k != 1:
v = n // k
d = (n - v) * a
if d < b:
n = v
c += d
else:
n = n // k
c += b
elif k == 1:
var = (n - 1) * a
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | import sys
input = sys.stdin.readline
n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
if k == 1:
print((n - 1) * a)
exit()
while n > 1:
if n < k:
ans += (n - 1) * a
break
if n % k != 0:
ans += n % k * a
n -= n % k
else:
while n % k... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
x = n
cost = 0
if k == 1:
print(int((x - 1) * a))
exit(0)
while x > 1:
if x < k:
cost += (x - 1) * a
break
rem = x % k
x -= rem
cost += a * rem
if rem == 0:
temp = x // k * (k - 1)
x //= k
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF VAR VAR V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
if k == 1:
n -= 1
print(n * A)
exit(0)
cnt = 0
while n > 1:
if n < k:
x = n - 1
cnt += x * A
break
r = n % k
if r != 0:
cnt += A * r
n -= r
else:
x = n - n // k
cnt += ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
c = 0
x = n
if k == 1:
c = a * (n - 1)
else:
while x >= k:
y = x % k
c += y * a
x -= y
c += min(b, a * (x - x // k))
x = x // k
c += a * (x - 1)
print(c) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_C... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
sum = 0
sumA = 0
sumB = 0
if k == 1:
sum = (n - 1) * A
else:
while n != 1:
if n % k != 0 and n > k:
sum = sum + A * (n % k)
n = n - n % k
elif n < k:
sum = sum + A * (n - 1)
n = n ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
cost = 0
if k != 1:
while n != 1:
if n < k:
cost += (n - 1) * A
n = 1
elif n % k == 0:
res = n // k
costA = B
costB = (n - res) * A
n = res
cost += ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR AS... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
s = 0
if k == 1:
print((n - 1) * A)
else:
while n // k * (k - 1) * A > B:
s += n % k * A + B
n //= k
print(s + (n - 1) * A) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_O... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, A, B = (int(input()) for i in range(4))
cost = 0
if k == 1:
print((n - 1) * A)
else:
while n > 1:
if n % k != 0:
m = n % k
n -= m
cost += A * (m - 1) if n < 1 else A * m
else:
m = n // k
cost += (n - m) * A if (n - m) * A < B else... | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | import sys
inf = float("inf")
abc = "abcdefghijklmnopqrstuvwxyz"
abd = {
"a": 0,
"b": 1,
"c": 2,
"d": 3,
"e": 4,
"f": 5,
"g": 6,
"h": 7,
"i": 8,
"j": 9,
"k": 10,
"l": 11,
"m": 12,
"n": 13,
"o": 14,
"p": 15,
"q": 16,
"r": 17,
"s": 18,
"t": ... | IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NU... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | def main():
n, k, a, b = (int(input()) for _ in "nkab")
r = 0
if k > 1:
while n >= k:
r += n % k * a
n //= k
r += min(b, n * (k - 1) * a)
print(r + (n - 1) * a)
main() | FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input().strip())
k = int(input().strip())
a = int(input().strip())
b = int(input().strip())
cost = 0
if k == 1:
cost = (n - 1) * a
else:
while n != 1:
if n % k == 0:
if b <= (n - n // k) * a:
cost += b
else:
cost += (n - n // k) * a
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | def run():
n, k, a, b = int(input()), int(input()), int(input()), int(input())
if n == 1:
print(0)
return
if k == 1:
print((n - 1) * a)
return
r = 0
while True:
if n < k:
print(r + (n - 1) * a)
return
rem = n % k
if rem ... | FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | x = int(input())
k = int(input())
A = int(input())
B = int(input())
ans = 0
while x != 1:
if x < k or k == 1:
ans += (x - 1) * A
x -= x - 1
elif x % k != 0:
ans += x % k * A
x -= x % k
else:
ans += min(B, (x - x // k) * A)
x = x // k
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, a, b = int(input()), int(input()), int(input()), int(input())
if k == 1:
print(a * (n - 1))
else:
ans = 0
while n > 1:
if n % k == 0:
nw = n // k
diff = n - nw
if a * diff < b:
ans += a * diff
else:
ans += b
... | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
res = 0
if k == 1:
print((n - 1) * a)
else:
while n != 1:
res += n % k * a
if b > n // k * (k - 1) * a:
res += n // k * (k - 1) * a
else:
res += b
n //= k
if n < k:
res... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP BIN_OP BIN_OP VAR VAR B... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
def fun(n, k, a, b):
if k == 1:
return (n - 1) * a
if n == 1:
return 0
if n < k:
return (n - 1) * a
return min(n % k * a + fun(n // k, k, a, b) + b, (n - 1) * a)
print(fun(n, k, a, b)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN BIN_OP BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP BI... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | import sys
n = int(input())
k = int(input())
a = int(input())
b = int(input())
coin = 0
if n == 1:
print("0")
sys.exit()
if k == 1:
print((n - 1) * a)
sys.exit()
sum = 0
while n != 1:
if n < k:
sum = sum + (n - 1) * a
break
if n % k != 0:
sum = sum + a * (n % k)
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
if n >= k and k != 1:
n1 = n
while True:
if n1 == 1:
break
if n1 < k:
ans += (n1 - 1) * a
break
if n1 % k != 0:
ans += n1 % k * a
n1 -= n1 % k
a... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP BI... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | x = int(input())
k = int(input())
a = int(input())
b = int(input())
cost = 0
av_a = 0
av_b = 0
if a == 0:
cost = 0
elif k == 1:
cost = (x - 1) * a
else:
while x > 1:
if x % k != 0:
if x > k:
w = x % k
x = x - w
cost = cost + w * a
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | def tanya(n, k, a, b):
if k == 1:
return (n - 1) * a
s = 0
while n > 1:
if n % k != 0 and n < k:
s += a * (n - 1)
n -= n - 1
elif n % k != 0:
s += a * (n % k)
n -= n % k
elif n % k == 0:
s += min(b, (n - n // k) * a)... | FUNC_DEF IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | def solve():
n = int(input())
k = int(input())
a = int(input())
b = int(input())
c = n
ans = 0
if k > 1:
while c != 1 and c > 0:
if c % k != 0:
if c > k:
ans += c % k * a
c = c - c % k
else:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1 or k > n:
print((n - 1) * a)
else:
x = n
coin = 0
while x != 1:
if x < k:
coin += (x - 1) * a
x = 1
elif x % k != 0:
r = x % k
coin += r * a
x -= r
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | import sys
n = int(sys.stdin.readline())
k = int(sys.stdin.readline())
A = int(sys.stdin.readline())
B = int(sys.stdin.readline())
if k == 1:
print((n - 1) * A)
else:
ans = 0
while True:
x = n // k * k
ans += (n - x) * A
n = x
if (n - n // k) * A <= B:
break
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | RealAnswer = 1e18
def KhelteThako(n, k, A, B, ans):
global RealAnswer
RealAnswer = min(RealAnswer, ans + (n - 1) * A)
if n <= 1:
if n == 1:
RealAnswer = min(RealAnswer, ans)
return
return
if n % k == 0:
KhelteThako(n / k, k, A, B, ans + B)
elif n > k... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN RETURN IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
if k > 1:
while n > 1:
new_n = max(1, n // k * k)
ans += (n - new_n) * a
n = new_n
while n % k == 0:
new_n = n // k
ans += min((n - new_n) * a, b)
n = new_n
else:
ans =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR WHILE BIN_OP... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
kapa = 0
if k == 1:
print((n - 1) * A)
else:
while n != 1:
if n < k:
kapa += (n - 1) * A
n = 1
elif n % k == 0:
kapa += min(B, (n - n // k) * A)
n //= k
else:
k... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BI... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, a, b = [int(input()) for _ in range(4)]
if k == 1:
print((n - 1) * a)
exit(0)
t, c = n, 0
while t > 1:
m = t % k
if m:
if t < k:
m -= 1
c += m * a
t -= m
else:
c += min(a * (k - 1) * t // k, b)
t //= k
print(c) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | x = []
for i in range(4):
x.append(int(input()))
n = x[0]
k = x[1]
a = x[2]
b = x[3]
cost = 0
x = n
while int(x) != 1:
if k == 1:
cost = cost + (x - 1) * a
x = 1
elif x < k:
cost = cost + (x - 1) * a
x = 1
elif x == k:
if b > (x - 1) * a:
cost = cost +... | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
x = n
cost = 0
while x != 1:
if k == 1:
cost += A * (x - 1)
x = 1
elif x % k == 0:
x = x / k
cost += min(B, A * (x * k - x))
elif x % k == 1:
x = x - 1
cost += A
else:
cost += A * ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VA... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if n == 1:
print(0)
exit()
if k == 1:
print((n - 1) * a)
exit()
ans = 0
while n != 1:
q, r = divmod(n, k)
if q == 0:
ans += (r - 1) * a
n = 1
elif r == 0:
ans += min(b, (n - n // k) * a)
n //=... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
coins = 0
while n > 1:
if n < k or k == 1:
coins += a * (n - 1)
n = 1
elif n == k:
coins += min(a * (n - 1), b)
n = 1
elif n % k == 0:
if a * (n - n // k) < b:
coins += a * (n - n // k)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBE... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, A, B = (int(input()) for i in range(4))
if k == 1:
print((n - 1) * A)
else:
x = n
ans = 0
while x != 1:
if 1 < x < k:
ans += (x - 1) * A
x = 1
elif x % k != 0:
ans += (x - x // k * k) * A
x = x // k * k
else:
d = x... | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VA... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | def solve(n, k, A, B):
if k == 1:
return A * (n - 1)
res = 0
while n >= k:
res += A * (n % k)
n -= n % k
diff = n - n // k
if A * diff > B:
res += B
n //= k
else:
res += A * (n - 1)
n = 1
res += A * (n - 1)
... | FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1:
print(a * (n - 1))
exit(0)
res = 0
while n > 1:
if n % k == 0:
res += min(a * (n - n // k), b)
n = n // k
else:
res += a * (n % k if n > k else n - 1)
n = n // k * k
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VA... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
while n != 1:
if n % k == 0:
d = n // k
if b >= (n - d) * a:
ans += (n - 1) * a
n = 1
else:
ans += b
n = d
else:
r = n % k
ans += r * a
n = ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR N... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | import sys
n = int(sys.stdin.readline().strip())
k = int(sys.stdin.readline().strip())
A = int(sys.stdin.readline().strip())
B = int(sys.stdin.readline().strip())
optimalPrice = 0
if k == 1:
optimalPrice = A * (n - 1)
else:
while n > 1:
if n % k == 0:
optimalPrice += min(B, A * (n - n // k)... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
mi = 0
if k == 1:
print((n - 1) * A)
exit()
while n != 1:
if n % k != 0:
mi += n % k * A
n -= n % k
if n <= 0:
mi -= A * abs(n - 1)
n = 1
else:
p = n
n /= k
mi += m... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
coins = 0
while n != 1:
if n % k == 0 and (n - n / k) * A > B:
coins += B
n /= k
elif n % k == 0:
coins += A * (n - 1)
n = 1
else:
coins += A * (n % k)
n = n - n % k
print(int(coins)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
mans = 0
if k == 1:
print((n - 1) * A)
else:
while n != 1:
ans = 0
if n % k == 0:
ans = n / k
mans += min((n - ans) * A, B)
n = int(n / k)
else:
x = n - n % k
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VA... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
ost = 0
res = 0
while a * (n // k) + b + n % k * a < n * a:
ost = ost + n % k * a
res = res + b
n = n // k
res = res + (n - 1) * a + ost
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
cost = 0
if n < k or k == 1:
print((n - 1) * a)
else:
while n > 1:
r = n % k
cost += r * a
n -= r
if n == 0:
cost -= a
break
cost += min(a * (n - int(n / k)), b)
n = int(n ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | from sys import stdin
n, k, a, b = [int(stdin.readline()) for i in range(4)]
ans = 0
if k == 1:
ans = a * (n - 1)
else:
while n > 1:
div, mod = divmod(n, k)
if mod:
ans += mod * a
n -= mod
if not n:
ans -= a
else:
x1 = a * ... | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | copys = int(input())
k = int(input())
A = int(input())
B = int(input())
time = 0
while copys != 1:
b = copys % k
if b != 0 and copys >= k and k != 1:
time += A * b
copys -= b
elif b == copys or k == 1:
time += A * (copys - 1)
copys = 1
break
elif b == 0 and B >= A... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, a, b = (int(input()) for i in range(4))
x, s = n, 0
if k <= 1:
print((x - 1) * a)
quit()
while x != 1:
if k > x:
s, x = s + (x - 1) * a, 1
elif x % k != 0:
s, x = s + x % k * a, x - x % k
elif x * (k - 1) // k * a > b:
s, x = s + b, x // k
else:
s, x = s + x... | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
count = 0
if n == 1:
print("0")
exit(0)
while n // k * a * (k - 1) > b:
count += n % k * a + b
n = n // k
count += (n - 1) * a
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP B... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
if k == 1:
print(A * (n - 1))
else:
SUM = 0
while n >= k:
if n % k != 0:
SUM += A * (n % k)
n -= n % k
else:
X = A * (n - n // k)
SUM += min(B, X)
n //= k
SUM +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input(""))
k = int(input(""))
a = int(input(""))
b = int(input(""))
ans = 0
while not n == 1:
m = n % k
n = n - m
ans = ans + m * a
if (n - n / k) * a > b:
n = n / k
ans = ans + b
else:
ans = ans + (n - 1) * a
n = 1
print(int(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP BI... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
x = n
cost = 0
worth_div = True
while x > 1:
if x % k == 0 and worth_div:
worth_div = (x - int(x / k)) * A > B
if worth_div:
cost += B
x = int(x / k)
else:
cost += A * (x - 1)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR I... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | def f(n, k, A, B):
if k == 1:
return (n - 1) * A
if n < k:
return A * (n - 1)
elif n % k == 0:
return min((n - 1) * A, B + f(n // k, k, A, B))
else:
return n % k * A + f(n - n % k, k, A, B)
n = int(input())
k = int(input())
A = int(input())
B = int(input())
print(f(n, k... | FUNC_DEF IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, A, B = int(input()), int(input()), int(input()), int(input())
if k == 1:
print((n - 1) * A)
else:
ans = (n - 1) * A
for i in range(1, 64):
pw = k**i
if pw > n:
break
cur_ans, x = i * B, n - pw
while pw > 0:
cur_ans += A * (x // pw)
x ... | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
sum = 0
x = n
if k == 1:
print((n - 1) * a)
else:
while x != 1:
if (x - 1) * a <= b:
break
if x < k:
sum += (x - 1) * a
x = 1
elif x % k != 0:
sum += a * (x % k)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR B... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | a = int(input())
b = int(input())
c = int(input())
d = int(input())
n = 0
if b == 1:
print(c * (a - 1))
else:
while True:
if a < b:
n += (a - 1) * c
a = 1
elif a % b != 0:
n += a % b * c
a = a - a % b
elif d > c * (a - int(a / b)):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
tot = 0
while n > 1:
if n < k or k == 1:
tot = tot + a * (n - 1)
n = 1
break
if a * (n - int(n / k)) > b:
if n % k == 0 and not k == 1:
n = n / k
tot = tot + b
else:
to... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR FUNC_CALL VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | o = lambda: int(input())
n = o()
k = o()
A = o()
B = o()
coins = 0
if k == 1:
print(A * (n - 1))
exit()
while n != 1:
if n % k != 0:
if n < k:
coins += A * (n - 1)
n -= n - 1
else:
coins += A * (n % k)
n -= int(n % k)
elif (n - n / k) * A <... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUM... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
sum = 0
while n != 1:
if k > 1:
if n % k == 0:
f = n // k
h = n - f
n = f
sum += min(h * a, b)
elif n > k:
sum += a * (n % k)
n = n - n % k
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_O... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
cost = 0
if k != 1:
while n != 1 and n > 0:
if n % k == 0:
n = n // k
cost = cost + min(n * (k - 1) * a, b)
else:
cost = cost + n % k * a
n = n - n % k
if n == 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
x = n
ans = 0
while x > 1:
if x % k == 0 and k != 1:
case1 = b
case2 = (x - x // k) * a
ans += min(case1, case2)
x = x // k
elif x >= k and k != 1:
ans += x % k * a
x -= x % k
else:
an... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
cost = 0
if k == 1:
print((n - 1) * a)
else:
while n >= k:
opa = n % k
cost += opa * a
n = n - opa
if n * (k - 1) * a > k * b:
cost += b
n = int(n / k)
else:
cost += (n... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
if k == 1:
if n > 1:
res = (n - 1) * A
print(res)
exit(0)
else:
print(0)
exit(0)
res = 0
while n > 1:
if n < k:
res += (n - 1) * A
break
r = n % k
res += r * A
n -= r
p... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NU... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | x = int(input())
k = int(input())
A = int(input())
B = int(input())
def test(i):
if i == 1:
return 0
else:
res = A * (i - 1)
if i >= k:
res = min(res, A * (i % k) + B + test(i // k))
return res
if k == 1:
print((x - 1) * A)
else:
print(test(x)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR FUN... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
c = 0
if k > n or k == 1:
c = (n - 1) * A
n = 1
while n > 1:
if n % k != 0:
if n > k:
c += A * (n % k)
n -= n % k
else:
c += A
n -= 1
else:
if (n - n / k) * A < B:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VA... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
ans = 0
if n == 1:
print(0)
elif k == 1:
print((n - 1) * A)
else:
while True:
if n == 1:
print(ans)
break
else:
ost = n % k
if ost == 0:
s = A * (n - n // k)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE NUMBER IF VAR NUMBER EXPR FUNC_CALL VA... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | from sys import stdin as cin
def main():
n = int(cin.readline())
k = int(cin.readline())
a = int(cin.readline())
b = int(cin.readline())
o = 0
if k == 1:
print((n - 1) * a)
return
while n > 1:
if n % k:
t = n - n // k * k
if t == n:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN WHILE VAR NUMBER IF BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1:
print((n - 1) * a)
exit(0)
cost = 0
while n > k:
rem = n % k
cost += rem * a
n -= rem
cost_a = (n - n // k) * a
n = n // k
cost += min(cost_a, b)
if n == k:
cost += min((n - 1) * a, b)
else:
cost += (n... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1:
print((n - 1) * a)
exit()
else:
c = 0
while True:
if k > n:
c += a * (n - 1)
print(int(c))
exit()
elif n % k != 0:
r = n - n // k * k
c += r * a
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUN... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
coin = 0
if k == 1:
print(int(A * (n - 1)))
else:
while n > 1:
if n % k == 0:
cur = (n - n / k) * A
if cur > B:
coin += B
else:
coin += cur
n /= k
e... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
x = n
ans = 0
if k == 1:
ans = (n - k) * A
print(ans)
else:
while x > 1:
if x % k == 0:
div = int(x / k)
temp1 = (x - div) * A
temp2 = B
if temp1 > temp2:
x = int(x / k... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
cost = 0
if k == 1:
cost = (n - 1) * A
else:
while n > 1:
if n % k == 0:
d = (k - 1) * n // k
if d * A < B:
n //= k
cost += A * d
else:
n //= k
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
x = n
c = 0
done = False
while x > 0:
if done:
c += x * A
x = 0
elif x % k != 0:
c += x % k * A
x -= x % k
elif B < (x - x // k) * A:
c += B
x = x // k
else:
c += (x - x // k) * A
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
l = []
s = 0
if k == 1:
print(a * (n - 1))
else:
while n != 1:
if n < k and n != 1:
s += (n - 1) * a
n = 1
elif n % k != 0:
s += n % k * a
n -= n % k
else:
s +=... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, A, B, sum = int(input()), int(input()), int(input()), int(input()), 0
while n > 1:
if n < k or k == 1:
sum += A * (n - 1)
break
next = n // k
if n % k == 0:
sum += min(A * (n - next), B)
else:
next *= k
sum += A * (n - next)
n = next
print(sum) | ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, a, b, s = int(input()), int(input()), int(input()), int(input()), 0
ans = 0
if n == 1:
print(0)
exit(0)
while n > 1:
if k == 1:
print((n - 1) * a)
exit(0)
if k > n:
print(ans + (n - 1) * a)
exit(0)
if n % k == 0:
ans = ans + min(b, (n - int(n / k)) * a)
... | ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_C... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | a = [0] * 4
for i in range(4):
a[i] = int(input())
cost = 0
while a[0] > 1:
if a[0] % a[1] == 0:
if a[1] == 1:
cost += (a[0] - 1) * a[2]
a[0] = 1
elif a[3] <= (a[0] - a[0] // a[1]) * a[2]:
a[0] = a[0] // a[1]
cost += a[3]
else:
... | ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR NUMBE... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, a, b = int(input()), int(input()), int(input()), int(input())
s = 0
while n > 1:
if n < k or k == 1:
s += (n - 1) * a
n = 1
continue
if n % k == 0:
if b < a * (n - n // k):
s += b
else:
s += a * (n - n // k)
n //= k
else:
... | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | x = int(input())
k = int(input())
a = int(input())
b = int(input())
c = 0
while x > 1:
if x % k > 0:
if x > k:
c += a * (x % k)
x -= x % k
else:
c += a * (x % k - 1)
x = 1
elif (x - x // k) * a >= b:
c += b
x = x // k
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
res = 0
while n > k:
if n % k > 0:
res += n % k * A
n -= n % k
dif = n - n // k
if dif * A > B:
res += B
n = n // k
else:
res += (n - 1) * A
n = 1
if n == k:
dif = n - n // k
if di... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
B = int(input())
summ = 0
while n != 1:
if k == 1 or n < k:
summ += A * (n - 1)
break
if n % k != 0:
times = n - n // k * k
summ += A * times
n -= times
else:
t2 = A * (n - n // k)
if B < t2:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR V... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | def solve():
n = int(input())
k = int(input())
A = int(input())
B = int(input())
if k == 1:
print((n - 1) * A)
return
cost = 0
x = n
while True:
if x == 1:
print(cost)
return
r = x % k
if r != 0:
if x > k:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RET... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
c1 = int(input())
c2 = int(input())
if k == 1:
k += n
ans = 0
while n > 1:
if n > k:
temp = n % k
ans += temp * c1
n -= temp
if n % k == 0:
ans += min(c2, (n - n // k) * c1)
n //= k
else:
ans += (n - 1) * c1
n = 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | I = lambda: int(input())
n = I()
k = I()
a = I()
b = I()
t = 0
if k == 1:
print(a * (n - 1))
else:
while n > 1:
if n >= k:
x = n % k
else:
x = n % k - 1
if x != 0:
t += x * a
n -= x
else:
y = n // k
xs = n - ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | GI = lambda: int(input())
GIS = lambda: map(int, input().split())
LGIS = lambda: list(GIS())
def main():
n = GI()
k = GI()
A = GI()
B = GI()
x = n
cost = 0
if k == 1:
return A * (x - 1)
while x > 1:
if x < k:
cost += A * (x - 1)
x = 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMB... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, a, b = [int(input()) for i in range(4)]
r = 0
if k - 1:
while n:
m, t = divmod(n, k)
r += t * a
n -= t
r += min(b, (n - m) * a)
n = m
r -= a
else:
r += (n - 1) * a
print(r) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
r = 0
if k == 1:
print((n - 1) * a)
return
while n != 1:
if n % k != 0:
r += n % k * a
n -= n % k
elif n < k:
r += (n - 1) * a
n = 1
else:
if n // k * (k - 1) * a < b:
r += n // k ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR B... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n, k, a, b = [int(input()) for i in range(4)]
sm = 0
x = n
if k == 1:
print((x - 1) * a)
exit()
while x != 1:
if x % k == 0:
a1 = x // k
sm += min(b, (x - a1) * a)
x //= k
else:
if x < k:
sm += (x - 1) * a
break
sm += a * (x % k)
x ... | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | def tanya():
n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
if k == 1:
ans = (n - 1) * a
n = 1
while n > 1:
rem = n % k
q = n // k
if rem == 0:
ans += min((n - n // k) * a, b)
n = n // k
else... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
if k == 1:
cost = a * (n - 1)
print(cost)
exit()
ans = 0
cost = 0
while n > 1:
cost += n % k * a
n -= n % k
if n > 1:
aa = b
bb = (n - n / k) * a
cost += min(aa, bb)
n = n // k
elif n == 0:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
count = 0
if k == 1:
count += (n - 1) * a
n = 1
else:
while n > 1:
if n % k == 0:
temp = n // k
if (n - temp) * a < b:
count += (n - temp) * a
n = temp
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
A = int(input())
if k == 1:
print((n - 1) * A)
exit()
B = int(input())
res = 0
x = n
k1 = (k - 1) * A
while x > 1:
res += A * (x % k)
x //= k
if x:
if B > x * k1:
res += (x * k - 1) * A
x = 1
else:
res += B
print(r... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | n = int(input())
k = int(input())
a = int(input())
b = int(input())
ans = 0
while n != 1 and n >= k and k != 1:
d = n % k
if d != 0:
ans = ans + d * a
n = n - d
ans = ans + min((n - n // k) * a, b)
n = n // k
else:
ans = ans + min((n - n // k) * a, b)
n = n //... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN ... |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x... | inf = 4557430888798830399
M = mod = 1000000007
mod2inv = 500000004
pt = lambda *a, **k: print(*a, **k, flush=True)
rd = lambda: map(int, input().split())
n = int(input())
k = int(input())
a = int(input())
b = int(input())
r = 0
if k == 1:
print((n - 1) * a)
return
while n:
if n % k:
r += n % k * a
... | ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NU... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.