Compute factorials and apply Wilson 's  theorem.
fact = 1 NEW_LINE for k in range ( 2 , n ) : NEW_LINE INDENT fact = fact * ( k - 1 ) NEW_LINE if ( ( fact + 1 ) % k == 0 ) : NEW_LINE INDENT print k NEW_LINE DEDENT DEDENT