You are viewing a single comment's thread. Return to all comments →
python
def decomposeNumberBy3and5(n): """If possible, get {3: a, 5: b}, such that n = a*3 + b*5. 3 has the priority.""" if n in (1, 2, 4, 7): return None match n % 3: case 0: return {3: n // 3, 5: 0} case 1: return {3: n // 3 - 3, 5: 2} # 1 = 5 * 2 - 3 * 3 case 2: return {3: n // 3 - 1, 5: 1} # 2 = 5 * 1 - 3 * 1 def decentNumber(n): if (decomp := decomposeNumberBy3and5(n)) is None: print(-1) else: print("5" * decomp[3]*3 + "3" * decomp[5]*5)
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
python