#24405: 想法


fire5386 (becaidorz)

School : 國立清華大學
ID : 115822
IP address : [101.12.152.136]
Last Login :
2024-06-23 16:07:36
d418. 00993 - Product of digits -- UVa993 | From: [61.230.3.179] | Post Date : 2021-02-14 21:44

如果n=1,直接輸出1

否則

對n做9~2的因數分解(從9開始因為9<33、8<222)

分解完後如果n不等於1,代表n無法變成以2~9的數字組成的數字

否則把剛剛分解的順數顛倒輸出就好了

範例:

216

216 % 9 = 0, list = "9", n = 24

24 % 9 != 0, list = "9", n = 24

24 % 8 = 0, list = "9, 8", n = 3

3 % 8 != 0, list = "9, 8", n = 3

3 % 7 != 0, list = "9, 8", n = 3

3 % 6 != 0, list = "9, 8", n = 3

3 % 5 != 0, list = "9, 8", n = 3

3 % 4 != 0, list = "9, 8", n = 3

3 % 3 = 0, list = "9, 8, 3", n = 1

1 % 3 != 0, list = "9, 8, 3", n = 1

1 % 2 = 0, list = "9, 8, 3", n = 1

完畢,n = 1,代表有辦法表示,其中最小符合的就是list顛倒後的389

 
ZeroJudge Forum