Square-free integers: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(6 intermediate revisions by 4 users not shown)
Line 35:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F SquareFree(_number)
V max = Int(sqrt(_number))
 
Line 56:
 
ListSquareFrees(1, 100)
ListSquareFrees(1000000000000, 1000000000145)</langsyntaxhighlight>
 
{{out}}
Line 98:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN
# count/show some square free numbers #
# a number is square free if not divisible by any square and so not divisible #
Line 179:
INT sf 1 000 000 := sf 100 000 + count square free( 100 001, 1 000 000 );
print( ( "square free numbers between 1 and 1 000 000: ", whole( sf 1 000 000, -6 ), newline ) )
END</langsyntaxhighlight>
{{out}}
<pre>Square free numbers from 1 to 145
Line 211:
square free numbers between 1 and 100 000: 60794
square free numbers between 1 and 1 000 000: 607926</pre>
 
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">squareFree?: function [n][
mx: to :integer sqrt n
loop 2..mx 'r ->
if zero? n % r ^ 2 -> return false
 
return true
]
 
sqFreeUpTo145: [1 2 3] ++ select 1..145 => squareFree?
print "Square-free integers from 1 to 145:"
loop split.every: 20 sqFreeUpTo145 'x ->
print map x 's -> pad to :string s 4
 
print ""
 
sqFreeUpToTrillion: select 1000000000000..1000000000145 => squareFree?
print "Square-free integers from 1000000000000 to 1000000000145:"
loop split.every: 5 sqFreeUpToTrillion 'x ->
print map x 's -> pad to :string s 14
 
print ""
 
print ["Number of square-free numbers between 1 and 100: " s100: <= 3 + enumerate 1..100 => squareFree?]
print ["Number of square-free numbers between 1 and 1000: " s1000: <= s100 + enumerate 101..1000 => squareFree?]
print ["Number of square-free numbers between 1 and 10000: " s10000: <= s1000 + enumerate 1001..10000 => squareFree?]
print ["Number of square-free numbers between 1 and 100000: " s100000: <= s10000 + enumerate 10001..100000 => squareFree?]
print ["Number of square-free numbers between 1 and 1000000: " s100000 + enumerate 100001..1000000 => squareFree?]</syntaxhighlight>
 
{{out}}
 
<pre>Square-free integers from 1 to 145:
1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31
33 34 35 37 38 39 41 42 43 46 47 51 53 55 57 58 59 61 62 65
66 67 69 70 71 73 74 77 78 79 82 83 85 86 87 89 91 93 94 95
97 101 102 103 105 106 107 109 110 111 113 114 115 118 119 122 123 127 129 130
131 133 134 137 138 139 141 142 143 145
 
Square-free integers from 1000000000000 to 1000000000145:
1000000000001 1000000000002 1000000000003 1000000000005 1000000000006
1000000000007 1000000000009 1000000000011 1000000000013 1000000000014
1000000000015 1000000000018 1000000000019 1000000000021 1000000000022
1000000000023 1000000000027 1000000000029 1000000000030 1000000000031
1000000000033 1000000000037 1000000000038 1000000000039 1000000000041
1000000000042 1000000000043 1000000000045 1000000000046 1000000000047
1000000000049 1000000000051 1000000000054 1000000000055 1000000000057
1000000000058 1000000000059 1000000000061 1000000000063 1000000000065
1000000000066 1000000000067 1000000000069 1000000000070 1000000000073
1000000000074 1000000000077 1000000000078 1000000000079 1000000000081
1000000000082 1000000000085 1000000000086 1000000000087 1000000000090
1000000000091 1000000000093 1000000000094 1000000000095 1000000000097
1000000000099 1000000000101 1000000000102 1000000000103 1000000000105
1000000000106 1000000000109 1000000000111 1000000000113 1000000000114
1000000000115 1000000000117 1000000000118 1000000000119 1000000000121
1000000000122 1000000000123 1000000000126 1000000000127 1000000000129
1000000000130 1000000000133 1000000000135 1000000000137 1000000000138
1000000000139 1000000000141 1000000000142 1000000000145
 
Number of square-free numbers between 1 and 100: 61
Number of square-free numbers between 1 and 1000: 608
Number of square-free numbers between 1 and 10000: 6083
Number of square-free numbers between 1 and 100000: 60794
Number of square-free numbers between 1 and 1000000: 607926</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SQUARE-FREE_INTEGERS.AWK
# converted from LUA
Line 252 ⟶ 316:
return(1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 285 ⟶ 349:
=={{header|C}}==
{{trans|Go}}
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <math.h>
Line 371 ⟶ 435:
free(sf);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 411 ⟶ 475:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <cstdint>
#include <iostream>
#include <string>
Line 468 ⟶ 532:
print_square_free_count(1, 1000000);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 502 ⟶ 566:
=={{header|D}}==
{{trans|Java}}
<langsyntaxhighlight lang="d">import std.array;
import std.math;
import std.stdio;
Line 580 ⟶ 644:
writefln(" from 1 to %d = %d", to, squareFree(1, to).length);
}
}</langsyntaxhighlight>
{{out}}
<pre>Square-free integers from 1 to 145:
Line 620 ⟶ 684:
 
For instance, the prime factorization of <tt>12</tt> is <code>2 * 2 * 3</code>, or in other words, <code>2<sup>2</sup> * 3</code>. The <tt>2</tt> repeats, so we know <tt>12</tt> isn't square-free.
<langsyntaxhighlight lang="factor">USING: formatting grouping io kernel math math.functions
math.primes.factors math.ranges sequences sets ;
IN: rosetta-code.square-free
Line 639 ⟶ 703:
1 145 10 12 ^ dup 145 + [ sq-free-show ] 2bi@ ! part 1
2 6 [a,b] [ 10 swap ^ ] map [ sq-free-count ] each ! part 2</langsyntaxhighlight>
{{out}}
<pre>
Line 677 ⟶ 741:
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: square_free? ( n -- ? )
dup 4 mod 0= if drop false exit then
3
Line 733 ⟶ 797:
 
main
bye</langsyntaxhighlight>
 
{{out}}
Line 773 ⟶ 837:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 06-07-2018
' compile with: fbc -s console
 
Line 861 ⟶ 925:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre> 1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31
Line 895 ⟶ 959:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 975 ⟶ 1,039:
fmt.Printf(" from %d to %d = %d\n", 1, n, len(squareFree(1, n)))
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,016 ⟶ 1,080:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.List.Split (chunksOf)
import Math.NumberTheory.Primes (factorise)
import Text.Printf (printf)
Line 1,056 ⟶ 1,120:
printSquareFrees 20 1 145
printSquareFrees 5 1000000000000 1000000000145
printSquareFreeCounts [100, 1000, 10000, 100000, 1000000] 1 1000000</langsyntaxhighlight>
 
{{out}}
Line 1,097 ⟶ 1,161:
=={{header|J}}==
'''Solution:'''
<langsyntaxhighlight lang="j">isSqrFree=: (#@~. = #)@q: NB. are there no duplicates in the prime factors of a number?
filter=: adverb def ' #~ u' NB. filter right arg using verb to left
countSqrFree=: +/@:isSqrFree
thru=: <. + i.@(+ *)@-~ NB. helper verb</langsyntaxhighlight>
 
'''Required Examples:'''
<langsyntaxhighlight lang="j"> isSqrFree filter 1 thru 145 NB. returns all results, but not all are displayed
1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31 33 34 35 37 38 39 41 42 43 46 47 51 53 55 57 58 59 61 62 65 66 67 69 70 71 73 74 77 78 79 82 83 85 86 87 89 91 93 94 95 97 101 102 103 105 106 107 109 110 111 113 114 115 118 119 122 123 127 129 130 131...
100 list isSqrFree filter 1000000000000 thru 1000000000145 NB. ensure that all results are displayed
Line 1,124 ⟶ 1,188:
608
1 countSqrFree@thru&> 10 ^ 2 3 4 5 6 NB. count square free ints for 1 to each of 100, 1000, 10000, 10000, 100000 and 1000000
61 608 6083 60794 607926</langsyntaxhighlight>
 
=={{header|Java}}==
{{trans|Go}}
<langsyntaxhighlight lang="java">import java.util.ArrayList;
import java.util.List;
 
Line 1,196 ⟶ 1,260:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,356 ⟶ 1,420:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Primes
 
const maxrootprime = Int64(floor(sqrt(1000000000145)))
Line 1,399 ⟶ 1,463:
squarefreebetween(1000000000000, 1000000000145)
squarefreecount([100, 1000, 10000, 100000], 1000000)
</langsyntaxhighlight> {{output}} <pre>
The squarefree numbers between 1 and 145 are:
1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23
Line 1,435 ⟶ 1,499:
=={{header|Kotlin}}==
{{trans|Go}}
<langsyntaxhighlight lang="scala">// Version 1.2.50
 
import kotlin.math.sqrt
Line 1,490 ⟶ 1,554:
j -> println(" from 1 to $j = ${squareFree(1..j).size}")
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,532 ⟶ 1,596:
=={{header|Lua}}==
This is a naive method, runs in about 1 second on LuaJIT.
<langsyntaxhighlight lang="lua">function squareFree (n)
for root = 2, math.sqrt(n) do
if n % (root * root) == 0 then return false end
Line 1,564 ⟶ 1,628:
{1, 1000000}
}
for _, example in pairs(testCases) do run(unpack(example)) end</langsyntaxhighlight>
{{out}}
<pre>From 1 to 145:
Line 1,606 ⟶ 1,670:
=={{header|Maple}}==
 
<syntaxhighlight lang="maple">
<lang Maple>
with(NumberTheory):
with(ArrayTools):
Line 1,648 ⟶ 1,712:
 
seq(cat(sfgroups[i], " from 1 to ", 10^(i+1)), i = 1..5);
</syntaxhighlight>
</lang>
{{out}}<pre>
[1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30, 31, 33,
Line 1,705 ⟶ 1,769:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">squareFree[n_Integer] := DeleteCases[Last /@ FactorInteger[n], 1] === {};
findSquareFree[n__] := Select[Range[n], squareFree];
findSquareFree[45]
findSquareFree[10^9, 10^9 + 145]
Length[findSquareFree[10^6]]</langsyntaxhighlight>
{{out}}
<pre>{1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43}
Line 1,736 ⟶ 1,800:
=={{header|Nanoquery}}==
{{trans|AWK}}
<langsyntaxhighlight lang="nanoquery">def is_square_free(n)
if n < 2^2
return true
Line 1,775 ⟶ 1,839:
square_free(1, 10000, false)
square_free(1, 100000, false)
square_free(1, 1000000, false)</langsyntaxhighlight>
{{out}}
<pre>
Line 1,808 ⟶ 1,872:
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight Nimlang="nim">import math, strutils
 
 
Line 1,863 ⟶ 1,927:
echo "\nNumber of square-free integers:\n"
for n in [100, 1_000, 10_000, 100_000, 1_000_000]:
echo " from $1 to $2 = $3".format(1, n, squareFree(1, n).len)</langsyntaxhighlight>
 
{{out}}
Line 1,903 ⟶ 1,967:
</pre>
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">
let squarefree (number: int) : bool =
let max = Float.of_int number |> sqrt |> Float.to_int |> (fun x -> x + 2) in
Line 1,939 ⟶ 2,003:
print_squarefree_integers (1000000000000, 1000000000146)
;;
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,989 ⟶ 2,053:
{{works with|Free Pascal}}
As so often, marking/sieving multiples of square of primes to speed things up.
<langsyntaxhighlight lang="pascal">program SquareFree;
{$IFDEF FPC}
{$MODE DELPHI}
Line 2,150 ⟶ 2,214:
 
Count_x10;
end.</langsyntaxhighlight>
{{out}}
<pre style="height:35ex">Square free numbers from 1 to 145
Line 2,201 ⟶ 2,265:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use ntheory qw/is_square_free moebius/;
 
sub square_free_count {
Line 2,222 ⟶ 2,286:
my $c = square_free_count(10**$n);
print "The number of square-free numbers between 1 and 10^$n (inclusive) is: $c\n";
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,239 ⟶ 2,303:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">square_frees</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">start</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">finish</span><span style="color: #0000FF;">)</span>
Line 2,267 ⟶ 2,331:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" from %,d to %,d = %,d\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span><span style="color: #000000;">len</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,306 ⟶ 2,370:
 
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
import math
 
Line 2,329 ⟶ 2,393:
ListSquareFrees( 1, 100 )
ListSquareFrees( 1000000000000, 1000000000145 )
</syntaxhighlight>
</lang>
 
'''Output:'''
Line 2,366 ⟶ 2,430:
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
 
(define (not-square-free-set-for-range range-min (range-max (add1 range-min)))
Line 2,408 ⟶ 2,472:
(count-square-free-numbers 10000)
(count-square-free-numbers 100000)
(count-square-free-numbers 1000000))</langsyntaxhighlight>
 
{{out}}
Line 2,448 ⟶ 2,512:
The prime factoring algorithm is not really the best option for finding long runs of sequential square-free numbers. It works, but is probably better suited for testing arbitrary numbers rather than testing every sequential number from 1 to some limit. If you know that that is going to be your use case, there are faster algorithms.
 
<syntaxhighlight lang="raku" perl6line># Prime factorization routines
sub prime-factors ( Int $n where * > 0 ) {
return $n if $n.is-prime;
Line 2,491 ⟶ 2,555:
say "\nThe number of square─free numbers between 1 and {$_} (inclusive) is: ",
+(1 .. .Int).race.grep: &is-square-free;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,529 ⟶ 2,593:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program displays square─free numbers (integers > 1) up to a specified limit. */
numeric digits 20 /*be able to handle larger numbers. */
parse arg LO HI . /*obtain optional arguments from the CL*/
Line 2,563 ⟶ 2,627:
if _>=0 then do; x= _; r= r + q; end
end /*while q>1*/
return r /*R is the integer square root of X. */</langsyntaxhighlight>
This REXX program makes use of &nbsp; '''linesize''' &nbsp; REXX program (or BIF) &nbsp; which is used to determine the screen width (or linesize) of the terminal (console); &nbsp; not all REXXes have this BIF.
 
Line 2,601 ⟶ 2,665:
 
The number of square─free numbers between 1 and 1000000 (inclusive) is: 607926
</pre>
 
=={{header|RPL}}==
{{trans|Python}}
≪ DUP √ CEIL → n max
≪ 1 SF
2 max '''FOR''' root
'''IF''' n root SQ MOD NOT '''THEN''' 1 CF max 'root' STO '''END'''
'''NEXT'''
1 FS?
≫ ≫ '<span style="color:blue">SQFREE?</span>' STO
≪ {} ROT ROT '''FOR''' n '''IF''' n <span style="color:blue">SQFREE?</span> '''THEN''' n + '''END NEXT'''
≫ '<span style="color:blue">TASK1</span>' STO
≪ 0 ROT ROT '''FOR''' n '''IF''' n <span style="color:blue">SQFREE?</span> '''THEN''' 1 + '''END NEXT'''
≫ '<span style="color:blue">TASK2</span>' STO
 
1 145 <span style="color:blue">TASK1</span>
1 1000 <span style="color:blue">TASK2</span>
{{out}}
<pre>
2: { 1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31 33 34 35 37 38 39 41 42 43 46 47 51 53 55 57 58 59 61 62 65 66 67 69 70 71 73 74 77 78 79 82 83 85 86 87 89 91 93 94 95 97 101 102 103 105 106 107 109 110 111 113 114 115 118 119 122 123 127 129 130 131 133 134 137 138 139 141 142 143 145 }
1: 608
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require "prime"
 
class Integer
Line 2,625 ⟶ 2,713:
puts "#{count} square-frees upto #{n}" if markers.include?(n)
end
</syntaxhighlight>
</lang>
{{out}}
<pre>1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31
Line 2,659 ⟶ 2,747:
=={{header|Rust}}==
{{trans|C++}}
<langsyntaxhighlight lang="rust">fn square_free(mut n: usize) -> bool {
if n & 3 == 0 {
return false;
Line 2,719 ⟶ 2,807:
n *= 10;
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,751 ⟶ 2,839:
</pre>
===Rust FP===
<syntaxhighlight lang="rust">fn square_free(x: usize) -> bool {
fn iter(x: usize, start: usize, prev: usize) -> bool {
let limit = (x as f64).sqrt().ceil() as usize;
match (start..=limit).skip_while(|i| x % i > 0).next() {
Some(v) => if v == prev {false}
else {iter(x / v, v, v)},
None => x != prev
}
}
iter(x, 2, 0)
}
 
fn main() {
for (up, to, nl_limit) in vec!((1, 145, 20), (1000000000000, 1000000000145, 6)) {
let free_nums = (up..=to).into_iter().filter(|&sf| square_free(sf));
println!("square_free numbers between {} and {}:", up, to);
for (index, free_num) in free_nums.enumerate() {
let spnl = if (index + 1) % nl_limit > 0 {' '} else {'\n'};
print!("{:3}{}", free_num, spnl)
}
println!("\n");
}
 
for limit in (2..7).map(|e| 10usize.pow(e)) {
let start = std::time::Instant::now();
let number = (1..=limit).into_iter().filter(|&sf| square_free(sf)).count();
let duration = start.elapsed().as_millis();
println!("Number of square-free numbers between 1 and {:7}: {:6} [time(ms) {:5}]",
limit, number, duration)
}
}</syntaxhighlight>
{{out}}
<pre>square_free numbers between 1 and 145:
1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31
33 34 35 37 38 39 41 42 43 46 47 51 53 55 57 58 59 61 62 65
66 67 69 70 71 73 74 77 78 79 82 83 85 86 87 89 91 93 94 95
97 101 102 103 105 106 107 109 110 111 113 114 115 118 119 122 123 127 129 130
131 133 134 137 138 139 141 142 143 145
 
square_free numbers between 1000000000000 and 1000000000145:
1000000000001 1000000000002 1000000000003 1000000000005 1000000000006 1000000000007
1000000000009 1000000000011 1000000000013 1000000000014 1000000000015 1000000000018
1000000000019 1000000000021 1000000000022 1000000000023 1000000000027 1000000000029
1000000000030 1000000000031 1000000000033 1000000000037 1000000000038 1000000000039
1000000000041 1000000000042 1000000000043 1000000000045 1000000000046 1000000000047
1000000000049 1000000000051 1000000000054 1000000000055 1000000000057 1000000000058
1000000000059 1000000000061 1000000000063 1000000000065 1000000000066 1000000000067
1000000000069 1000000000070 1000000000073 1000000000074 1000000000077 1000000000078
1000000000079 1000000000081 1000000000082 1000000000085 1000000000086 1000000000087
1000000000090 1000000000091 1000000000093 1000000000094 1000000000095 1000000000097
1000000000099 1000000000101 1000000000102 1000000000103 1000000000105 1000000000106
1000000000109 1000000000111 1000000000113 1000000000114 1000000000115 1000000000117
1000000000118 1000000000119 1000000000121 1000000000122 1000000000123 1000000000126
1000000000127 1000000000129 1000000000130 1000000000133 1000000000135 1000000000137
1000000000138 1000000000139 1000000000141 1000000000142 1000000000145
 
Number of square-free numbers between 1 and 100: 61 [time(ms) 0]
Number of square-free numbers between 1 and 1000: 608 [time(ms) 0]
Number of square-free numbers between 1 and 10000: 6083 [time(ms) 2]
Number of square-free numbers between 1 and 100000: 60794 [time(ms) 62]
Number of square-free numbers between 1 and 1000000: 607926 [time(ms) 1638]</pre>
 
=={{header|Scala}}==
This example uses a brute-force approach to check whether a number is square-free, and builds a lazily evaluated list of all square-free numbers with a simple filter. To get the large square-free numbers, it avoids computing the beginning of the list by starting the list at a given number.
<langsyntaxhighlight lang="scala">import spire.math.SafeLong
import spire.implicits._
 
Line 2,793 ⟶ 2,942:
fHelper(Vector[String](), formatted)
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,834 ⟶ 2,983:
In Sidef, the functions ''is_square_free(n)'' and ''square_free_count(min, max)'' are built-in. However, we can very easily reimplement them in Sidef code, as fast integer factorization methods are also available in the language.
 
<langsyntaxhighlight lang="ruby">func is_square_free(n) {
 
n.abs! if (n < 0)
Line 2,867 ⟶ 3,016:
var c = square_free_count(10**n)
say "The number of square─free numbers between 1 and 10^#{n} (inclusive) is: #{c}"
}</langsyntaxhighlight>
 
{{out}}
Line 2,910 ⟶ 3,059:
{{libheader|AttaSwift BigInt}}
 
<syntaxhighlight lang="text">import BigInt
import Foundation
 
Line 2,972 ⟶ 3,121:
break
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,985 ⟶ 3,134:
 
=={{header|Tcl}}==
<langsyntaxhighlight Tcllang="tcl">proc isSquarefree {n} {
for {set d 2} {($d * $d) <= $n} {set d [expr {($d+1)|1}]} {
if {0 == ($n % $d)} {
Line 3,042 ⟶ 3,191:
showCount 1 $H
}
</syntaxhighlight>
</lang>
{{out}}
<pre>Square-free integers in range 1..145 are:
Line 3,077 ⟶ 3,226:
=={{header|Visual Basic .NET}}==
{{trans|D}}
<langsyntaxhighlight lang="vbnet">Module Module1
 
Function Sieve(limit As Long) As List(Of Long)
Line 3,163 ⟶ 3,312:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>Square-free integers from 1 to 145:
Line 3,201 ⟶ 3,350:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
 
var isSquareFree = Fn.new { |n|
Line 3,234 ⟶ 3,383:
}
System.print(count)
}</langsyntaxhighlight>
 
{{out}}
Line 3,274 ⟶ 3,423:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">const Limit=1 + (1e12 + 145).sqrt(); // 1000001 because it fits this task
var [const]
BI=Import.lib("zklBigNum"), // GNU Multiple Precision Arithmetic Library
Line 3,294 ⟶ 3,443:
}
return(cnt,sink.close());
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">println("Square-free integers from 1 to 145:");
squareFree(1,145,True)[1].pump(Console.println,
T(Void.Read,14,False),fcn{ vm.arglist.apply("%4d ".fmt).concat() });
Line 3,301 ⟶ 3,450:
println("\nSquare-free integers from 1000000000000 to 1000000000145:");
squareFree(1000000000000,1000000000145,True)[1].pump(Console.println,
T(Void.Read,4,False),fcn{ vm.arglist.concat(" ") });</langsyntaxhighlight>
{{out}}
<pre style="height:35ex">
Line 3,333 ⟶ 3,482:
</pre>
 
<langsyntaxhighlight lang="zkl">n:=100; do(5){
squareFree(1,n)[0]:
println("%,9d square-free integers from 1 to %,d".fmt(_,n));
n*=10;
}</langsyntaxhighlight>
{{out}}
<pre>
9,476

edits