1. Problem
2. My Solution
import sys
n,b = sys.stdin.readline().rstrip().split()
n = list(n)
b = int(b)
weight = 1
sum = 0
for i in n[::-1]:
if i.isalpha():
sum += (ord(i)-55) * weight
else:
sum += int(i) * weight
weight *= b
print(sum)
1. Problem
2. My Solution
import sys
a,b = map(int,sys.stdin.readline().rstrip().split())
m = int(sys.stdin.readline().rstrip())
n = list(map(int,sys.stdin.readline().rstrip().split()))
weight = 1
decimal = 0
result = []
for i in n[::-1]:
decimal += i * weight
weight *= a
if decimal == 0:
print(0)
exit()
while(decimal != 0):
i,j = divmod(decimal, b)
result.append(j)
decimal = decimal//b
print(' '.join(list(map(str,result))[::-1]))
1. Problem
2. My Solution
import sys
def solution(n):
if n in dp:
return dp[n]
else:
dp[n] = solution(n-1) + solution(n-2)
return dp[n]
n = int(sys.stdin.readline().rstrip())
dp = {}
dp[1] = 1
dp[2] = 2
print(solution(n)%10007)
3. Others' Solution
4. Learned
1. Problem
2. Others' Solution
import sys
def solution(n):
if n in dp:
return dp[n]
else:
dp[n] = (solution(n-1)) + (solution(n-2)) * 2
return dp[n]
n = int(sys.stdin.readline().rstrip())
dp = {}
dp[1] = 1
dp[2] = 3
print(solution(n)%10007)