Task

Write a function to test if a number is   square-free.



A   square-free   is an integer which is divisible by no perfect square other
than   1   (unity).

For this task, only positive square-free numbers will be used.



Show here (on this page) all square-free integers (in a horizontal format) that are between:

   1   ───►   145     (inclusive)
   1 trillion   ───►   1 trillion + 145     (inclusive)


(One trillion = 1,000,000,000,000)



Show here (on this page) the count of square-free integers from:

   1   ───►   one hundred     (inclusive)
   1   ───►   one thousand     (inclusive)
   1   ───►   ten thousand     (inclusive)
   1   ───►   one hundred thousand     (inclusive)
   1   ───►   one million     (inclusive)


See also

   the Wikipedia entry:   square-free integer


with javascript_semantics
function square_frees(atom start, finish)
    sequence res = {}
    integer maxprime = get_maxprime(finish)
    while start<=finish do
        if square_free(start,maxprime) then
            res &= start
        end if
        start += 1
    end while
    return res
end function
 
procedure show_range(atom start, finish, integer jb, string fmt)
    sequence res = square_frees(start, finish)
    printf(1,"There are %d square-free integers from %,d to %,d:\n%s\n", 
             {length(res),start,finish,join_by(res,1,jb,"","\n",fmt)})
end procedure 
show_range(1,145,20,"%4d")
show_range(1e12,1e12+145,5,"%14d")

printf(1,"\nNumber of square-free integers:\n");
for i=2 to 6 do
    integer lim = power(10,i),
            len = length(square_frees(1,lim))
    printf(1,"  from %,d to %,d = %,d\n", {1,lim,len})
end for
