Store all triangular numbers up to N in a Set
while ( 1 ) : NEW_LINE INDENT x = i * ( i + 1 ) // 2 ; NEW_LINE if ( x >= n ) : NEW_LINE INDENT break ; NEW_LINE DEDENT tri . append ( x ) ; NEW_LINE i += 1 ; NEW_LINE DEDENT