[S S T T N
_Push_-1][S S S N
_Push_0][T N
T T _Read_STDIN_as_number][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T S S T _Subtract][S N
S _Duplicate][S S S N
_Push_0][T T T _Retrieve][S N
T _Swap][T S T T _Modulo][N
T T N
_If_0_Jump_to_Label_LOOP][S S T T N
_Push_-1][T S S N
_Multiply][T N
S T _Print_as_number]
-20 bytes thanks to @JoKing.
Letters S
(space), T
(tab), and N
(new-line) added as highlighting only.
[..._some_action]
added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
Explanation in pseudo-code:
Integer n = STDIN as integer
Integer i = -1
Start LOOP:
i = i - 1
if(n modulo-i is negative)
Go to next iteration of LOOP
else
i = i * -1
Print i
Exit with error: No exit defined
Example run: input = 9
Command Explanation Stack Heap STDIN STDOUT STDERR
SSTTN Push -1 [-1]
SSSN Push 0 [-1,0]
TNTT Read STDIN as integer [-1] {0:9} 9
NSSN Create Label_LOOP [-1] {0:9}
SSSTN Push 1 [-1,1] {0:9}
TSST Subtract top two (-1-1) [-2] {0:9}
SNS Duplicate top (-2) [-2,-2] {0:9}
SSSN Push 0 [-2,-2,0] {0:9}
TTT Retrieve [-2,-2,9] {0:9}
SNT Swap top two [-2,9,-2] {0:9}
TSTT Modulo top two (9%-2) [-2,-1] {0:9}
NTSN If neg.: Jump to Label_LOOP [-2] {0:9}
SSTTN Push -1 [-2,-1] {0:9}
TSST Subtract top two (-2-1) [-3] {0:9}
SNS Duplicate top (-2) [-3,-3] {0:9}
SSSN Push 0 [-3,-3,0] {0:9}
TTT Retrieve [-3,-3,9] {0:9}
SNT Swap top two [-3,9,-3] {0:9}
TSTT Modulo top two (9%-3) [-3,0] {0:9}
NTSN If neg.: Jump to Label_LOOP [-3] {0:9}
SSTTN Push -1 [-3,-1] {0:9}
TSSN Multiply top two (-3*-1) [3] {0:9}
TNST Print as integer [] {0:9} 3
error
Program stops with an error: No exit found.
1Can
n
be 1? – user202729 – 2018-06-20T10:41:39.180@user202729: In the 4th test-case
n = 1
. – Emigna – 2018-06-20T10:53:16.85715Maybe it would have been more challenging to get the power part instead of the prime part. As it is, this is just "Get the lowest factor that isn't 1" – Jo King – 2018-06-20T13:48:14.967