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(NumberTheory):
with(ArrayTools):
 
squareFree := proc(n::integer)
 if mul(PrimeFactors(n)) = n then return true;
 else return false; end if;
 return true;
end proc:
 
sfintegers := Array([]):
 
for count from 1 to 145 do
 if squareFree(count) then Append(sfintegers, count); end if;
end do:
 
print(sfintegers):
 
sfintegers := Array([]):
 
for count from 10^12 to 10^12+145 do
 if squareFree(count) then Append(sfintegers, count); end if;
end do:
 
print(sfintegers):
 
sfgroups := Array([]):
sfcount := 0:
 
for number from 1 to 100 do
 if squareFree(number) then sfcount += 1: end if:
end do:
Append(sfgroups, sfcount):
 
for expon from 3 to 6 do
 for number from 10^(expon - 1) to 10^expon do
  if squareFree(number) then sfcount += 1: end if:
 end do:
 Append(sfgroups, sfcount):
end do:
 
seq(cat(sfgroups[i], " from 1 to ", 10^(i+1)), i = 1..5); 
 