45 lines
1.1 KiB
Text
45 lines
1.1 KiB
Text
program square_free_integers;
|
|
show_square_frees([1..145]);
|
|
show_square_frees([1000000000000..1000000000145]);
|
|
count_square_frees();
|
|
|
|
proc count_square_frees();
|
|
loop init
|
|
limit := 100;
|
|
count := 0;
|
|
n := 1;
|
|
while limit <= 1000000 do
|
|
if n = limit then
|
|
print(str count + " square free numbers <= " + str limit);
|
|
limit *:= 10;
|
|
end if;
|
|
if square_free(n) then
|
|
count +:= 1;
|
|
end if;
|
|
n +:= 1;
|
|
end loop;
|
|
end proc;
|
|
|
|
proc show_square_frees(nums);
|
|
loop for n in nums do
|
|
if square_free(n) then
|
|
nprint(lpad(str n, 15));
|
|
if (col +:= 1) mod 5 = 0 then
|
|
print;
|
|
end if;
|
|
end if;
|
|
end loop;
|
|
print;
|
|
end proc;
|
|
|
|
proc square_free(n);
|
|
loop init r := 2;
|
|
while r*r <= n do
|
|
if n mod (r*r) = 0 then
|
|
return False;
|
|
end if;
|
|
r +:= 1;
|
|
end loop;
|
|
return True;
|
|
end proc;
|
|
end program;
|