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


def is_square_free(n)
        if n < 2^2
                return true
        end
 
        for root in range(2, int(sqrt(n)))
                if (n % (root ^ 2)) = 0
                        return false
                end
        end
        return true
end
 
def square_free(low, high, show_values)
        print format("%d-%d: ", low, high)
        leng = len(str(low)) + len(str(high)) + 3
        count = 0
        for i in range(low, high)
                if is_square_free(i)
                        count += 1
                        if show_values
                                if leng > 110
                                        println
                                        leng = 0
                                end
                                print format("%d ", i)
                                leng += len(str(i)) + 1
                        end
                end
        end
        print format("count=%d\n\n", count)
end
 
square_free(1, 145, true)
square_free(10^12, 10^12 + 145, true)
square_free(1, 100, false)
square_free(1, 1000, false)
square_free(1, 10000, false)
square_free(1, 100000, false)
square_free(1, 1000000, false)