Find factors in Math . sqrt ( x ) time
for ( let i = 2 ; i <= Math . sqrt ( x ) ; i ++ ) { if ( x % i == 0 ) { fact . push ( i ) ; if ( x / i != i ) fact . push ( x / i ) ; factors . add ( i ) ; factors . add ( x / i ) ; } } let found = false ; let k = fact . length ; for ( let i = 0 ; i < k ; i ++ ) {