Problem:


Score : 300 points

Problem Statement

To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:

1 yen (the currency of Japan)

6 yen, 6^2(=36) yen, 6^3(=216) yen, ...

9 yen, 9^2(=81) yen, 9^3(=729) yen, ...

At least how many operations are required to withdraw exactly N yen in total?

It is not allowed to re-deposit the money you withdrew.

Constraints

1 \leq N \leq 100000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If at least x operations are required to withdraw exactly N yen in total, print x.

Sample Input 1

127

Sample Output 1

4

By withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.

Sample Input 2

3

Sample Output 2

3

By withdrawing 1 yen three times, we can withdraw 3 yen in three operations.

Sample Input 3

44852

Sample Output 3

16



Sample input:
127


Sample output:
4

Submission status: Wrong Answer

Solution code:
N = int(input())

six_max_pow = 6
nine_max_pow = 5

count = 0
tmp = 0

while N > 0 and (nine_max_pow > 1 or six_max_pow > 1):

    tmp_nine = pow(9, nine_max_pow)
    tmp_six = pow(6, six_max_pow)

    if tmp_nine >= tmp_six:
        if N // tmp_nine >= 1:
            N -= tmp_nine
            count += 1
        else:
            nine_max_pow = max(1, nine_max_pow - 1)
    else:
        if N // tmp_six >= 1:
            N -= tmp_six
            count += 1
        else:
            six_max_pow = max(1, six_max_pow - 1)

while N > 0:

    if N // 9 >= 1:
        if N % 6 < 6 and N >= 17:
            N -= 6
            count += 1
        else:
            N -= 9
            count += 1

    elif N // 6 >= 1:
        N -= 6
        count += 1

    else:
        break


print(count + N)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
temp_N = N
# judge = True
ans = 0
temp = 9
temp_list = [1,2,3,4,5]
while 100000>temp:
    temp_list.append(temp)
    temp *=9 
temp = 6
while 100000>temp:
    temp_list.append(temp)
    temp *=6 
temp_list=sorted(temp_list)
# print(temp_list)
for i in range(1,len(temp_list)+1):
    if temp_N%temp_list[-i] == 0 and temp_list[-i]>5:
        # print(temp_list[-i])
        print(N//temp_list[-i])
        sys.exit() 
    else:
        judge = True
        while judge:
            if N - temp_list[-i] > 9 and (temp_list[-i] >5):
                # print(N)
                # print(temp_list[-i])
                N -= temp_list[-i]
                ans+=1
            else:
                judge = False
# print(N)
# print(N//9)
# print(N//6)
# print(N)
if N%9 < N%6:
    ans += N//9
    N = N%9
    # N -= 9*N//9
else:
    ans += N//6
    N = N%6
    # N -= 6*N//6
# print(N)
# print(ans)
print(N+ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*
import math
# 整数の入力
N = int(raw_input())

def dfn(an):
	s = math.floor( math.log(an, 9))
	return (an - 9 ** s)
	
def dfs(an):
	s=math.floor(math.log(an, 6))
	return (an-6**s)

r=N
c=0
while r>=5:
	r1=dfn(r)
	r2=dfs(r)
	r=min(r1,r2)
	c+=1

mm= int(c+r)

Submission status: Wrong Answer

Solution code:
N = int(input())

def hikidashi(n):
    if 35 >= n:
        tmp1 = n//9 + (n%9)//6 + (n%9)%6
        tmp2 = n//6 + n%6

        if tmp1 == tmp2:
            if n >= 9:
                return 9
            elif n >= 6:
                return 6
            else:
                return 1
        elif tmp1 > tmp2:
            if n >= 6:
                return 6
            else:
                return 1
        else:
            if n >= 9:
                return 9
            else:
                return 1

    else:
        count = 0
        while True:
            tmp = pow(9, count)
            if tmp > n:
                break
            n9 = tmp
            count += 1

        count = 0
        while True:
            tmp = pow(6, count)
            if tmp > n:
                break
            n6 = tmp
            count += 1
        return max(n6, n9)


result = 0
while N != 0:
    result += 1
    N = N - hikidashi(N)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = 0 # count
L1 = [6**k for k in range(0, 7)]
L2 = [9**k for k in range(1, 6)]
L = L1 + L2
L.sort()
i = 0
while n > 0:
    if 12 <= n <= 14:
        n = n - 6 * 2
        x = x + 2
    if n >= L[11 - i]:
        n = n - L[11 -i]
        x = x + 1
    else:
        i = i + 1
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())

def hikidashi(n):
    if 35 >= n:
        tmp1 = n//9 + (n%9)//6 + (n%9)%6
        tmp2 = n//6 + n%6

        if tmp1 == tmp2:
            if n >= 9:
                return 9
            elif n >= 6:
                return 6
            else:
                return 1
        elif tmp1 > tmp2:
            if n >= 6:
                return 6
            else:
                return 1
        else:
            if n >= 9:
                return 9
            else:
                return 1

    else:
        count = 0
        while True:
            tmp = pow(9, count)
            if tmp > n:
                break
            n9 = tmp
            count += 1

        count = 0
        while True:
            tmp = pow(6, count)
            if tmp > n:
                break
            n6 = tmp
            count += 1
        return max(n6, n9)


result = 0
while N != 0:
    result += 1
    print(N,hikidashi(N))
    N = N - hikidashi(N)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [9**a for a in range(1, 6)]
b = [6**a for a in range(1, 6)]
count = 0
for i in range(1, 6):
    if n > 6:
        while n >= a[-i] or n >= b[-i]:
            if (n // a[-i] + n % a[-i]) < (n // b[-i] + n % b[-i]):
                if n >= a[-i]:
                    n -= a[-i]
                    count += 1
            else:
                if n >= b[-i]:
                    n -= b[-i]
                    count += 1

count += n
print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def sum_num(num):
    sum = 0
    for i in range(len(num)):
        sum += int(num[i])
    return sum

N = int(stdin.readline().rstrip())

x = 0

while N != 0:
    x_6 = Base_10_to_n(N, 6)
    x_9 = Base_10_to_n(N, 9)
    if (sum_num(x_9) <= sum_num(x_6)):
        if (len(x_9) >= len(x_6)):
            N -= 9**(len(x_9)-1)
            x += 1
        else:
            N -= 6**(len(x_6)-1)
            x += 1
    else:
        if (len(x_6) >= len(x_9)):
            N -= 6**(len(x_6)-1)
            x += 1
        else:
            N -= 9**(len(x_9)-1)
            x += 1

print(x)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
temp_N = N
# judge = True
ans = 0
temp = 9
temp_list = [1,2,3,4,5]
while 100000>temp:
    temp_list.append(temp)
    temp *=9 
temp = 6
while 100000>temp:
    temp_list.append(temp)
    temp *=6 
temp_list=sorted(temp_list)
# print(temp_list)
for i in range(1,len(temp_list)+1):
    if temp_N%temp_list[-i] == 0 and temp_list[-i]>5:
        print(temp_list[-i])
        print(N//temp_list[-i])
        sys.exit() 
    else:
        judge = True
        while judge:
            if N - temp_list[-i] > 9 and (temp_list[-i] >5):
                # print(N)
                # print(temp_list[-i])
                N -= temp_list[-i]
                ans+=1
            else:
                judge = False
# print(N)
# print(N//9)
# print(N//6)
# print(N)
if N%9 < N%6:
    ans += N//9
    N = N%9
    # N -= 9*N//9
else:
    ans += N//6
    N = N%6
    # N -= 6*N//6
# print(N)
# print(ans)
print(N+ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

import copy
import sys

def solve(n, actions, offset):

    res = 0
    val = 1000000
    if n == 0 or len(actions) == 0:
        return(offset)
    while (val > n):
        val = actions.pop()
    if val == 1:
        return(n + offset)
    while n >= val * 2:
        res += 1
        n -= val
    tmp = 1000000
    i = 0
    while n >= 0:
        tmp = min(tmp, solve(copy.copy(n), copy.copy(actions), copy.copy(i)))
        i += 1
        n -= val
    return(tmp + res + offset)


n = int(input())

res = 0

actions = [1]

for i in range(1, 6 + 1):
    actions.append(6 ** i)
    actions.append(9 ** i)

print(solve(n, actions, 0))

Submission status: Wrong Answer

Solution code:
n = int(input())

nine = []
six = []


for i in range(10):
	nine.append(9**i)
	six.append(6**i)



nine.extend(six)
nine.sort()

count = 0
while n > 0:
	if n < 6 : 
		count += n
		n = 0
	elif n == 6:
		count +=1
		n = 0 
	else :
		i = 0
		while nine[i+1] <= n and (n-nine[i+1] > 5 ) :
			i += 1
		
		count += 1
		n = n - nine[i]

		
		
print count

Submission status: Wrong Answer

Solution code:
def power_of_six(n):
    now = 1
    power = 0
    while now <= n:
        now = now * 6
        power = power + 1
    return power-1

def power_of_nine(n):
    now = 1
    power = 0
    while now <= n:
        now = now * 9
        power = power + 1
    return power-1

def main():
    N = input()
    x = 0
    powsix = 0
    pownine = 0
    while N > 0:
        if N < 18:
            if N<12:
                x = x + N/9 + N%9
                break
            else:
                x = x + N/6 + N%6
                break
        else:
            powsix = power_of_six(N)
            pownine = power_of_nine(N)
            if 6**powsix > 9**pownine:
                N = N - 6**powsix
                x = x + 1
            else:
                N = N - 9**pownine
                x = x + 1
    print(x)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [9**a for a in range(1, 6)]
b = [6**a for a in range(1, 6)]
count = 0
for i in range(1, 6):
    if n > 6:
        while n >= a[-i] or n >= b[-i]:
            if (n // a[-i] + n % a[-i]) < (n // b[-i] + n % b[-i]):
                if n >= a[-i]:
                    n -= a[-i]
                    count += 1
                    print(n, count)
            else:
                if n >= b[-i]:
                    n -= b[-i]
                    count += 1

count += n
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

nine = []
six = []


for i in range(10):
	nine.append(9**i)
	six.append(6**i)



nine.extend(six)
nine.sort()

print nine
count = 0
while n > 0:
	if n < 6 : 
		count += n
		n = 0
	elif n == 6:
		count +=1
		n = 0 
	else :
		i = 0
		while nine[i+1] <= n and (n-nine[i+1] > 5 ) :
			i += 1
		
		count += 1
		n = n - nine[i]
		print n
		
		
print count

Submission status: Wrong Answer

Solution code:
arr = [1]
for i in range(1, 10):
    if 6 ** i < 100000:
        arr.append(6 ** i)
    if 9 ** i < 100000:
        arr.append(9 ** i)

arr.sort(reverse=True)

n = 44852
#n = 127
# n=3


def wari(k, l=0):
    # print(k)
    if k == 0:
        return l
    i = 0
    while k < arr[i]:
        i += 1
    a = int(k / arr[i])
    b = k % arr[i]
    wari1 = wari(b, a+l)

    if i < len(arr)-1:
        c = int(k / arr[i+1])
        d = k % arr[i+1]
        wari2 = wari(d, c+l)
        if wari1 < wari2:
            return wari1
        else:
            return wari2
    return wari1


print(wari(n))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
memo = [0]*(N+1)
memo[0] = 0

for i in range(1,N+1):
	memo[i] = memo[i-1]+1
	for j in range(1,math.floor(math.log(i,6))+1):
		memo[i] = min(memo[i],memo[i-pow(6,j)]+1)
	for j in range(1,math.floor(math.log(i,9))+1):
		memo[i] = min(memo[i],memo[i-pow(9,j)]+1)

print(memo[N])

Submission status: Wrong Answer

Solution code:
def max_pay(price, unit):
    i = 1
    while price >= unit**i:
        i += 1
    return unit**(i - 1)

def max_pay_2(price, unit):
    i = 1
    while price >= unit*i:
        i += 1
    return unit*(i - 1)


price = int(input())
count = 0

while price != 0:
    if price // 6 == 0:
        count += price
        break
    else:
        price -= max(max_pay(price, 9), max_pay(price, 6))
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

units = [19683, 15552, 2592, 2187, 432, 243, 73, 27, 12, 3, 2]

count = N % 3
N = N // 3
for unit in units:
    while(N >= unit):
        N -= unit
        count += 1
count += N

print(count)

Submission status: Wrong Answer

Solution code:
# input
N = int(input())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def min_69(X):
    count = 0
    while X > 14:
        X_6 = Base_10_to_n(X, 6)
        X_9 = Base_10_to_n(X, 9)
        if 6 ** (len(X_6) - 1) >= 9 ** (len(X_9) - 1):
            count += 1
            X = X - 6 ** (len(X_6) - 1)
        else:
            count += 1
            X = X - 9 ** (len(X_9) - 1)
    if X == 1 or X == 6 or X == 9:
        count += 1
    if X == 2 or X == 7 or X == 10 or X == 12:
        count += 2
    if X == 3 or X == 8 or X == 11 or X == 13:
        count += 3
    if X == 4 or X == 14:
        count += 4
    if X == 5:
        count += 5
    return count

ans = min_69(N)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

import sys
sys.setrecursionlimit(1000000) 

money_list = []
for i in range(1,8):
    if 6**i < n:
        money_list.append(6**i)
for i in range(1,5):
    if 9**i < n:
        money_list.append(9**i)

money_list.sort()
money_list.reverse()
        
def dfs(sum_money,sum_times,money):
    global ans
    if sum_times >= ans:
        return
    if sum_money > n:
        ans = min(ans, sum_times-1+n-sum_money+money)
        return
    for i in money_list:
        dfs(sum_money+i,sum_times+1,i)
        
ans = n
dfs(0,0,0)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
for cand in reversed(sorted([9**i for i in range(1, 6)] + [6**i for i in range(1,7)])):
    if N >= cand:
        i = 1
        while N >= i * cand:
            i += 1
        N = N - (i - 1) * cand
        ans += i - 1

    if N == 0:
        break

ans += N

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def sum_num(num):
    sum = 0
    for i in range(len(num)):
        sum += int(num[i])
    return sum

N = int(stdin.readline().rstrip())

x = 0

while N != 0:
    x_6 = Base_10_to_n(N, 6)
    x_9 = Base_10_to_n(N, 9)
    if (len(x_9) > len(x_6)):
        N -= 9**(len(x_9)-1)
        x += 1
    if (len(x_9) == len(x_6)):
        if (sum_num(x_9) <= sum_num(x_6)):
            N -= 9**(len(x_9)-1)
            x += 1
        else:
            N -= 6**(len(x_6)-1)
            x += 1
    else:
        N -= 6**(len(x_6)-1)
        x += 1

print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())

def conv(x, n):
    nchar = '0123456789'

    result = ''

    while x > 0:
        result = nchar[x % n] + result
        x = x // n

    return result

l = [int(e) for e in reversed(list(str(conv(N, 9))))]

res = min(l[0], 1 + l[0] % 6)

for e in l[1:]:
    res += min(e, e // 4 + e % 4)

print(res)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
# judge = True
ans = 0
temp = 9
temp_list = [1,2,3,4,5]
while 100000>temp:
    temp_list.append(temp)
    temp *=9 
temp = 6
while 100000>temp:
    temp_list.append(temp)
    temp *=6 
temp_list=sorted(temp_list)
# print(temp_list)
for i in range(1,len(temp_list)+1):
    if N%temp_list[-i] == 0:
        print(N//temp_list[-i])
        sys.exit() 
    else:
        judge = True
        while judge:
            if N - temp_list[-i] > 9 and (temp_list[-i] >5):
                # print(N)
                # print(temp_list[-i])
                N -= temp_list[-i]
                ans+=1
            else:
                judge = False
# print(N)
# print(N//9)
# print(N//6)
# print(N)
if N%9 < N%6:
    ans += N//9
    N = N%9
    # N -= 9*N//9
else:
    ans += N//6
    N = N%6
    # N -= 6*N//6
# print(N)
# print(ans)
print(N+ans)
# print(N)
# print(ans)
# print(ans+N)

# temp_9 = []
# temp_6 = []
# judge = True

# while judge:
#     for i in range(1,len(temp_9)+1):
#         if N -temp_9[-i] >=0:
#             N -= temp_9[-i]
#             print(N)
#     judge = False
# print(N) 

# # while N > temp:
# #     temp *= 9
# #     ans += 1    
# # N = N - temp/9
# # print(N)

Submission status: Wrong Answer

Solution code:
N = int(input())

def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    
    return str(n%b)

count = 0
#Main
while True:
    #終了処理
    if 12 <= N and N <= 14:
        count += int(N/6)
        count += N%6
        break
    elif N < 6:
        count += N
        break

    list_num = list(base10to(N, 9))
    if len(list_num)-1 != 0:
        Max_nine = 9 ** (len(list_num)-1)
        #print('Max_nine = {0}'.format(Max_nine))
    else:
        Max_nine = 0

    list_num = list(base10to(N, 6))
    Max_six = 6 ** (len(list_num)-1)
    #print('Max_six = {0}'.format(Max_six))

    #大きさ比べ
    if Max_nine > Max_six:
        N -= Max_nine
    else:
        N -= Max_six

    count += 1
    #print('N = {0}'.format(N))

print(count)
#基本方針は最大値を一番初めに引き出す

Submission status: Wrong Answer

Solution code:
import math
n=int(raw_input())
a=[10**6]*(n+1)
for i in xrange(1,min(7,n+1)):
    a[i]=i
for i in xrange(7,n+1):
    fac9=int(math.log(i,9))
    fac6=int(math.log(i,6))
    while(fac9>=0):
        a[i]=min(a[i],1+a[i-9**fac9])
        fac9-=1
    while(fac6>=0):
        a[i]=min(a[i],1+a[i-6**fac6])
        fac6-=1
print a[n]

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
l = [0]

for i in range(1, n+1):
    a = int(math.log(i, 6))
    b = int(math.log(i, 9))
    l += [min([l[i-6**p] + 1 for p in range(1, a+1)] + [l[i-9**q] + 1 for q in range(1, b+1)] + [l[i-1] + 1])]

print(l[n])

Submission status: Wrong Answer

Solution code:
def abc099_c():
    n = int(input())
    if n == 3:
        return 3
    vals = [6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049][::-1]

    count = n % 3
    n -= count
    while n:
        for val in vals:
            if n >= val and (n - val) != 3:
                n -= val
                count += 1
                break

    return count

print(abc099_c())

Submission status: Wrong Answer

Solution code:
N = int(input())

choice = [9 ** i for i in range(1, 6)] + [6 ** i for i in range(1, 6)]

op = 0

available = [n for n in choice if n <= N]
while len(available) > 0:
    N -= max(available)
    op += 1
    available = [n for n in choice if n <= N]
op += N

print(op)

Submission status: Wrong Answer

Solution code:
import math

i1 = int(input())

counter = 0
a1 = []
for i in range(6):
    a1.append(6 ** (i + 1))
for i in range(5):
    a1.append(9 ** (i + 1))
a1.sort()

while i1 >= 6:
    for i in range(6 + 5):
        iX = 10 - i
        if math.floor(i1 / a1[iX]) > 0:
            i1 = i1 - a1[iX]
            counter += 1
            break
counter += i1
print (counter)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def sum_num(num):
    sum = 0
    for i in range(len(num)):
        sum += int(num[i])
    return sum

N = int(stdin.readline().rstrip())

x = 0

while N > 0:
    x_6 = Base_10_to_n(N, 6)
    x_9 = Base_10_to_n(N, 9)
    if (len(x_9) > len(x_6)):
        N -= 9**(len(x_9)-1)
        x += 1
    if (len(x_9) == len(x_6)):
        if (sum_num(x_9) <= sum_num(x_6)):
            N -= 9**(len(x_9)-1)
            x += 1
        else:
            N -= 6**(len(x_6)-1)
            x += 1
    else:
        N -= 6**(len(x_6)-1)
        x += 1

print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve():
    N = int(input())
    if N<=0 or N>100000:
        return;
    b= []
    i=0
    while(6**i<N):
        b.append(6**i)
        i+=1
    i=1
    while(9**i<N):
        b.append(9**i)
        i+=1
    b.sort()
    x = np.zeros(N)
    x[0] = 1
    for itms in b:
        for vol in range(N):
            dif = vol-itms
            if (dif+1 >= 0):
                if (dif==-1):
                    x[vol]=1
                elif(x[vol]==0 or x[vol]>x[dif]+1):
                    x[vol] = x[dif]+1
    print(int(x[N-1]))

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:

n = int(input())
ones = 1
sixes = [1,6,6**2,6**3,6**4,6**5,6**6]
nines = [9,9**2,9**3,9**4,9**5]

sixes.extend(nines)
sixes.sort(reverse=1)

ans = 0

for i in sixes:
    if i <= n:
        while i <= n:
            n -= i
            ans +=1
            print(i)
        
    if n == 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

#units = [1]
#
#for i in range(1, 7):
#    units.append(6**i)
#
#for i in range(1, 6):
#    units.append(9**i)
units = [19683, 15552, 2592, 2187, 432, 243, 73, 27, 12, 3, 2, 1]

count = N % 3
N = N // 3
for unit in units:
    while(N >= unit):
        #print(unit)
        N -= unit
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
# judge = True
ans = 0
temp = 9
temp_list = [1,2,3,4,5]
while 100000>temp:
    temp_list.append(temp)
    temp *=9 
temp = 6
while 100000>temp:
    temp_list.append(temp)
    temp *=6 
temp_list=sorted(temp_list)
# print(temp_list)
for i in range(1,len(temp_list)+1):
    if N - temp_list[-i] == 0:
        print("1")
        sys.exit() 
    else:
        judge = True
        while judge:
            if N - temp_list[-i] > 9 and (temp_list[-i] >5):
                # print(N)
                # print(temp_list[-i])
                N -= temp_list[-i]
                ans+=1
            else:
                judge = False
# print(N)
# print(N//9)
# print(N//6)
# print(N)
if N%9 < N%6:
    ans += N//9
    N = N%9
    # N -= 9*N//9
else:
    ans += N//6
    N = N%6
    # N -= 6*N//6
# print(N)
# print(ans)
print(N+ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    a = input()
    a = int(a)
    b = a

    lst = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]

    lst = np.sort(lst)[::-1]
    use = [0] *12

    ans = 0

    while a > 0:
        for i in range(12):
            if a >= lst[i]:
                a = a - lst[i]
                ans+=1
                use[i] = use[i] + 1
                break

if __name__ == "__main__":
        main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())

count = 0
while True:
    n6 = 6**int(np.log(N)/np.log(6))
    n9 = 9**int(np.log(N)/np.log(9))
    if n6 > n9:
        N = N - n6
    else:
        N = N - n9
    print(N)
    count += 1
    if N == 0: break
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

N = int(input())

wd = []
for i in range(1, 6):
    wd.append(9**i)
for i in range(1, 7):
    wd.append(6**i)
wd.append(1)
wd.sort()

if N in wd:
    print(1)
else:
    a = bisect_left(wd, N)
    cnt = 0
    while N > 0:
        N -= wd[a-1]
        cnt += 1
        if N in wd:
            print(cnt+1)
            break
        else:
            a = bisect_left(wd, N)

Submission status: Wrong Answer

Solution code:
def abc099_c():
    n = int(input())
    if n == 3:
        return 3
    vals = [6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049][::-1]

    count = n % 3
    n -= count
    while n:
        if n == 12:
            count += 2
            break
        for val in vals:
            if n >= val:
                n -= val
                count += 1
                break

    return count

print(abc099_c())

Submission status: Wrong Answer

Solution code:
#C
N=44852
n=N
count=0
while n!=0:
    six_multi=[6**i for i in range(7) if 6**i<=n]
    nine_multi=[9**i for i in range(6) if 9**i<=n]
    draw=max(set(six_multi+nine_multi))
    print(draw)
    n=n-draw
    count=count+1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
#print(N)

A,B,C = 0,0,0


Possible = []
Possible.append(1)
for i in range(1,8):
    Possible.append(6**i)
for i in range(1,6):
    Possible.append(9**i)

Possible.sort()
#print(Possible)

def MInt(Possible,N):
    for i in range(len(Possible)):
        if Possible[i]>N:
            return Possible[i-1]

def CountIncrement(Possible,Count,N):
    C = 0

    base = MInt(Possible,N)
    #print("base = ",base)

    # if base == 1:
    #     return (Count + N),0

    if N<36:
        #print("here")
        cand = [1,2,3,4,5,1,2,3,1,2,3,2,3,4,5,6,7,2,3,4,3,4,5,4,5,6,3,4,5,5,5,6,4,5,6]
        return (Count + cand[N-1]),0
    
    n = 0
    for i in range(100):
        if base*i < N:
            n += 1
        else:
            return (Count + (n-1)),(N- (n-1)*base)


def Counting(N):
    Count = 0
    for i in range(10):
        Count,N = CountIncrement(Possible,Count,N)
        #print(i,Count,N)
        if(N==0):
            return Count
        
print(Counting(N))

Submission status: Wrong Answer

Solution code:
N = int(input())

def conv(x, n):
    nchar = '0123456789'

    result = ''

    while x > 0:
        result = nchar[x % n] + result
        x = x // n

    return result

l = [int(e) for e in reversed(list(str(conv(N, 9))))]

res = l[0]

for e in l[1:]:
    res += min(e, e // 4 + e % 4)

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
money_list = (59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1)
ans = 0
for i in money_list:
  while n >= i:
    if (46656*2) <= n:
      n -= 46656
      ans += 1
    elif (6561*2) <= n < (7776+6561):
      n -= 6561
      ans += 1
    elif (729*2) <= n < (1296+729) or (729*3) <= n < (1259+729+216):
      n -= 729
      ans += 1
    elif (81*3) <= n <= (81*3+2) or (81*3+6) <= n < (216+36): #249: #(245):
      n -= 81
      ans += 1
    elif 12 <= n < 15:
      n -= 6
      ans += 1
    else:
      n -= i
      ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
list = []
for i in [6,5,4,3,2,1]:

    for r in [9,6,]:
        while n > r**i:
            n = n - r**i
            list.append(r**i)
            print(n)


length = len(list) + n
print(length)

Submission status: Wrong Answer

Solution code:
N = int(input())


def shortest(target):
    Min = float("inf")
    for i in range(target // 9 + 1):
        temp = target - i * 9
        for j in range(temp // 6 + 1):
            k = temp - j * 6
            Min = min(Min, i + j + k)
    return Min


f = []
for i in range(36):
    f.append(shortest(i))


def hoge(kind, target):
    i = 0
    while kind**i <= target:
        i += 1
    rest = target - kind**(i - 1)
    return rest


candidates = []
target = N
count = 0
while target >= 36:
    six_rest = hoge(6, target)
    nine_rest = hoge(9, target)
    if six_rest < 36:
        candidates.append(count + 1 + f[six_rest])
    if nine_rest < 36:
        candidates.append(count + 1 + f[nine_rest])
    if six_rest < nine_rest:
        target = six_rest
    else:
        target = nine_rest
    count += 1

if len(candidates) == 0:
    print(f[target])
else:
    print(min(candidates))

Submission status: Wrong Answer

Solution code:
def func(n, k):
    i6 = 1
    i9 = 1
    while(i6*6 <= n):
        i6*=6
    while(i9*9 <= n):
        i9*=9
    n6 = n - i6
    n9 = n - i9
    # print(n, i6, i9)
    if n < 6:
        return k+n
    elif n6 == 0 or n9 == 0:
        return k+1
    elif n % 9 != 0 and n % 6 == 0:
        return func(n6, k+1)
    elif n % 9 == 0 and n % 6 != 0:
        return func(n9, k+1)
    else:
        return func(min(n6, n9), k+1)

N = int(input())
print (func(N, 0))

Submission status: Wrong Answer

Solution code:
N = int(input())


def solve():
    global N
    ans = 0
    a = []
    values = sorted([1] + [pow(6, _) for _ in range(1, 10)] + [pow(9, _) for _ in range(1, 10)])
    while N > 0:
        if 12 <= N <= 14:
            ans += 2 + (N - 12)
            break
        else:
            for i in range(len(values)):
                if N < values[i]:
                    ans += 1
                    a.append((values[i - 1], N))
                    N -= values[i-1]
                    break
                elif N == values[i]:
                    ans += 1
                    a.append((values[i], N))
                    N -= values[i]
                    break
            if N == 0:
                break
    return ans


if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
n = int(input())


def judge(nx):
    i = 1
    while 1:
        mon = 9 ** i
        n1 = nx - mon
        if n1 < 0:
            # print(n1, mon, nx, i)
            if i > 1:
                ans1 = 9 ** (i-1)
                break
        i += 1
    i = 1
    while 1:
        mon = 6 ** i
        n1 = nx - mon
        if n1 < 0:
            # print(n1, mon, nx, i)
            if i > 1:
                ans2 = 6 ** (i-1)
                break
        i += 1
    # print(ans1, ans2)
    if ans1 > ans2:
        return ans1
    else:
        return ans2


ans = 0
nx = n
while nx >= 6:
    # print('-------')
    # print(nx)
    d = judge(nx)
    # print(d)
    # print('-------')
    nx -= d
    ans += 1

# print(nx)
ans += nx

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = 0
while N != 0:
	if int(N / 81) >= 1:
		N -= 81 * int(N / 81)
	elif int(N / 36) >= 1:
		N -= 36 * int(N / 36)
	elif int(N / 9) >= 1:
		N -= 9 
	elif int(N / 6) >= 1:
		N -= 6 
	else:
		N -= 1
	x += 1
print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve():
    N = int(input())
    b= []
    i=0
    while(6**i<N):
        b.append(6**i)
        i+=1
    i=1
    while(9**i<N):
        b.append(9**i)
        i+=1
    b.sort()
    x = np.zeros(N,dtype='int64')
    for itms in b:
        for vol in range(N):
            dif = vol-itms
            if (dif+1 >= 0):
                if (dif==-1):
                    x[vol]=1
                elif(x[vol]==0 or x[vol]>x[dif]+1):
                    x[vol] = x[dif]+1
    print(x[N-1])

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
money = []
N=int(input())
n=9
m=6
while n < 100000:
    money.append (n)
    n = n*9

while m < 100000:
    money.append (m)
    m = m*6

money.sort()
money.reverse()

times = 0

for i in money:
    times += int(N/i)
    N -= int(N/i) * i
    if N<36:
        break

possibility = []
for j in range(0,int(N/9)+1):
    M = N-9*j
    possibility.append(j + int(M/6) + M%6)

print (times + min(possibility))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [9**a for a in range(1, 6)]
b = [6**a for a in range(1, 6)]
count = 0
for i in range(1, 6):
    if n > 6:
        while n > a[-i] or n > b[-i]:
            if (n // a[-i] + n % a[-i]) < (n // b[-i] + n % b[-i]):
                if n > a[-i]:
                    n -= a[-i]
                    count += 1
            else:
                if n > b[-i]:
                    n -= b[-i]
                    count += 1

count += n
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0

while(N != 0):
    ans += 1
    # print(N)
    max_list = [1, ]

    for tmp in [6, 9]:
        alpha = 0
        while(N >= tmp ** alpha):
            alpha += 1
            # print(tmp**alpha)
        max_list.append(int(tmp**(alpha - 1)))
    # print(max_list, N)
    N = N - max(max_list)
print(ans)