それはタイトルのすべてです…
Take as input a positive integer n>=12
and… do
what the title says.
はい、これはOEIS A187924 にあります。
Some test cases
12 -> 912
13 -> 11713
14 -> 6314
15 -> 915
16 -> 3616
17 -> 15317
18 -> 918
19 -> 17119
20 -> 9920
40 -> 1999840
100-> 99999999999100
This is code-golf.
Shortest code in bytes wins!
Befunge、81バイト
&>00p0v1+:0^
>00g->#^_:0v
0g10g-#^[email protected]>
>0p:55+/:v>
^1+g01%+55_$^
少なくとも n =
70まで処理することができます。その後、ほとんどの実装でスタックセルのサイズがオーバーフローし始める値があります。そうでない場合は、見つけ出すのを待っている。
これらの制約から、99より大きい n の値を処理しようとするのは面倒ではありません。つまり、単純に値が
n で終わるかどうかを簡単にテストできます。 100を法とする値を n と比較する。
以下は、コードの詳細な内訳です。
Read
n from stdin and save in memory.
Initialize
the test value v to 0 and start the main loop,
incrementing v up front.
Test if
v%n == 0
, and if not return to the start of the main
loop.
Test if
v%100 == n
, and if not return to the start of the main
loop.
Sum the
digits in v by repeatedly adding v modulo 10 and
dividing v by 10.
Test if the
sum is equal to n, and if not return to the start of the
main loop.
Otherwise
output v and exit.