728x90
반응형

VERSION 2.0

 

 

import sys

#설탕 봉지는 3kg , 5kg 봉지

#5x+3y = N

# 22g 5kg 봉지==> 22-(5*4(개)) ==2 22-(5*3(개)) == 7 22-(5*2(개)) == 12
# 6KG 5kg 봉지 ==? 6-(5*1(개)) ==1
N = int(sys.stdin.readline())
a = N//5 #첫 갯수
#print('a : ' ,a)
res = 0

if N%5 ==0:
    res += (N//5)
else:
    while True:
        B = N -(5*a)
        #print('B : ', B)
    
        if B%3 ==0:
            res+= a+ (B//3)
            break
        elif B%3 !=0:
            a-=1
        if a <= 0 :
            if N%3 == 0:
                res += N//3
            else:
                res = -1
            break
print(res)

VERSION 1.0

 

import sys
N = int(sys.stdin.readline())
five , three = 0 , 0
M = N
while True:
    if N%5 == 0:
        five = N//5
        break
    else:
        M -=3
        if M >= 0:
            three+=1
            if M %5 ==0:
                five = M//5
                break
        else:
            break
if (3*three) + (5*five) != N:
    print(-1)
else:
    result = five + three
    print(result)
728x90
반응형

+ Recent posts