Nth Square free number | Function to find nth square free number ; To maintain count of square free number ; Loop for square free numbers ; Checking whether square of a number is divisible by any number which is a perfect square ; If number is square free ; If the cnt becomes n , return the number ; Driver Code
function squareFree ( n ) { let cnt = 0 ; for ( let i = 1 ; ; i ++ ) { let isSqFree = true ; for ( let j = 2 ; j * j <= i ; j ++ ) { if ( i % ( j * j ) == 0 ) { isSqFree = false ; break ; } } if ( isSqFree == true ) { cnt ++ ; if ( cnt == n ) return i ; } } } let n = 10 ; document . write ( " " + squareFree ( n ) ) ;