Square-free integers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) |
(Certainly there is a point for improvement, examples are displaying (American, not Italian :-)) [https://en.wikipedia.org/wiki/Spaghetti_code Spaghetti code]) |
||
Line 1: | Line 1: | ||
{{draft task}} |
{{draft task}} |
||
;Task: |
;Task: |
||
Write a function to test if a number is ''square-free''. |
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 |
A ''square-free'' is an integer which is divisible by no perfect square other |
||
Line 15: | Line 13: | ||
::* '''1''' ───► '''145''' (inclusive) |
::* '''1''' ───► '''145''' (inclusive) |
||
::* '''1''' trillion ───► '''1''' trillion + '''145''' (inclusive) |
::* '''1''' trillion ───► '''1''' trillion + '''145''' (inclusive) |
||
(One trillion = 1,000,000,000,000) |
(One trillion = 1,000,000,000,000) |
||
Show here (on this page) the count of square-free integers from: |
Show here (on this page) the count of square-free integers from: |
||
Line 26: | Line 22: | ||
::* '''1''' ───► one hundred thousand (inclusive) |
::* '''1''' ───► one hundred thousand (inclusive) |
||
::* '''1''' ───► one million (inclusive) |
::* '''1''' ───► one million (inclusive) |
||
;See also: |
;See also: |
||
Line 34: | Line 29: | ||
=={{header|C}}== |
=={{header|C}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
{{improve|C|[https://en.wikipedia.org/wiki/Considered_harmful Considered harmful]}} |
|||
<lang c>#include <stdio.h> |
<lang c>#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
Line 129: | Line 125: | ||
return 0; |
return 0; |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31 |
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 |
33 34 35 37 38 39 41 42 43 46 47 51 53 55 57 58 59 61 62 65 |
||
Line 164: | Line 158: | ||
from 1 to 10000 = 6083 |
from 1 to 10000 = 6083 |
||
from 1 to 100000 = 60794 |
from 1 to 100000 = 60794 |
||
from 1 to 1000000 = 607926 |
from 1 to 1000000 = 607926</pre> |
||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
Line 192: | Line 185: | ||
2 6 [a,b] [ 10 swap ^ ] map [ sq-free-count ] each ! part 2</lang> |
2 6 [a,b] [ 10 swap ^ ] map [ sq-free-count ] each ! part 2</lang> |
||
{{out}} |
{{out}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31 |
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 |
33 34 35 37 38 39 41 42 43 46 47 51 53 55 57 58 59 61 62 65 |
||
Line 224: | Line 216: | ||
6083 square-free integers from 1 to 10000 |
6083 square-free integers from 1 to 10000 |
||
60794 square-free integers from 1 to 100000 |
60794 square-free integers from 1 to 100000 |
||
607926 square-free integers from 1 to 1000000 |
607926 square-free integers from 1 to 1000000</pre> |
||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{improve|C|[https://en.wikipedia.org/wiki/Considered_harmful Considered harmful]}} |
|||
<lang go>package main |
<lang go>package main |
||
Line 311: | Line 303: | ||
fmt.Printf(" from %d to %d = %d\n", 1, 1000000, len(squareFree(1, 1000000))) |
fmt.Printf(" from %d to %d = %d\n", 1, 1000000, len(squareFree(1, 1000000))) |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31 |
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 |
33 34 35 37 38 39 41 42 43 46 47 51 53 55 57 58 59 61 62 65 |
||
Line 347: | Line 337: | ||
from 1 to 10000 = 6083 |
from 1 to 10000 = 6083 |
||
from 1 to 100000 = 60794 |
from 1 to 100000 = 60794 |
||
from 1 to 1000000 = 607926 |
from 1 to 1000000 = 607926</pre> |
||
</pre> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{improve|C|[https://en.wikipedia.org/wiki/Considered_harmful Considered harmful]}} |
|||
{{trans|Go}} |
{{trans|Go}} |
||
<lang java>import java.util.ArrayList; |
<lang java>import java.util.ArrayList; |
||
Line 421: | Line 411: | ||
} |
} |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31 |
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 |
33 34 35 37 38 39 41 42 43 46 47 51 53 55 57 58 59 61 62 65 |
||
Line 457: | Line 445: | ||
from 1 to 10000 = 6083 |
from 1 to 10000 = 6083 |
||
from 1 to 100000 = 60794 |
from 1 to 100000 = 60794 |
||
from 1 to 1000000 = 607926 |
from 1 to 1000000 = 607926</pre> |
||
</pre> |
|||
=={{header|Kotlin}} |
=={{header|Kotlin}} |
||
{{improve|C|[https://en.wikipedia.org/wiki/Considered_harmful Considered harmful]}} |
|||
{{trans|Go}} |
{{trans|Go}} |
||
<lang scala>// Version 1.2.50 |
<lang scala>// Version 1.2.50 |
||
Line 528: | Line 516: | ||
System.out.printf(" from %d to %d = %d\n", 1, 1000000, squareFree(1, 1000000).size) |
System.out.printf(" from %d to %d = %d\n", 1, 1000000, squareFree(1, 1000000).size) |
||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
1 2 3 5 6 7 10 11 13 14 15 17 19 21 22 23 26 29 30 31 |
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 |
33 34 35 37 38 39 41 42 43 46 47 51 53 55 57 58 59 61 62 65 |
||
Line 564: | Line 550: | ||
from 1 to 10000 = 6083 |
from 1 to 10000 = 6083 |
||
from 1 to 100000 = 60794 |
from 1 to 100000 = 60794 |
||
from 1 to 1000000 = 607926 |
from 1 to 1000000 = 607926</pre> |
||
</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
Line 681: | Line 666: | ||
This REXX program makes use of '''linesize''' REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console); not all REXXes have this BIF. |
This REXX program makes use of '''linesize''' REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console); not all REXXes have this BIF. |
||
The '''LINESIZE.REX''' REXX program is included here ──► [[LINESIZE.REX]]. |
The '''LINESIZE.REX''' REXX program is included here ──► [[LINESIZE.REX]].<br> |
||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
(Shown at three-quarter size.) |
(Shown at three-quarter size.) |
||
<pre style="font-size:75%">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 |
|||
<pre style="font-size:75%"> |
|||
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</pre> |
|||
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 |
|||
</pre> |
|||
{{out|output|text= when using the input of: <tt> 1000000000000 1000000000145 </tt>}} |
{{out|output|text= when using the input of: <tt> 1000000000000 1000000000145 </tt>}} |
||
Line 703: | Line 685: | ||
1000000000099 1000000000101 1000000000102 1000000000103 1000000000105 1000000000106 1000000000109 1000000000111 1000000000113 1000000000114 |
1000000000099 1000000000101 1000000000102 1000000000103 1000000000105 1000000000106 1000000000109 1000000000111 1000000000113 1000000000114 |
||
1000000000115 1000000000117 1000000000118 1000000000119 1000000000121 1000000000122 1000000000123 1000000000126 1000000000127 1000000000129 |
1000000000115 1000000000117 1000000000118 1000000000119 1000000000121 1000000000122 1000000000123 1000000000126 1000000000127 1000000000129 |
||
1000000000130 1000000000133 1000000000135 1000000000137 1000000000138 1000000000139 1000000000141 1000000000142 1000000000145 |
1000000000130 1000000000133 1000000000135 1000000000137 1000000000138 1000000000139 1000000000141 1000000000142 1000000000145</pre> |
||
</pre> |
|||
{{out|output|text= when using the (separate runs) inputs of: <tt> 1 -100 </tt> (and others) |
{{out|output|text= when using the (separate runs) inputs of: <tt> 1 -100 </tt> (and others) |
||
⚫ | |||
<pre> |
|||
⚫ | |||
The number of square─free numbers between 1 and 1000 (inclusive) is: 608 |
The number of square─free numbers between 1 and 1000 (inclusive) is: 608 |
||
Line 715: | Line 695: | ||
The number of square─free numbers between 1 and 100000 (inclusive) is: 60794 |
The number of square─free numbers between 1 and 100000 (inclusive) is: 60794 |
||
The number of square─free numbers between 1 and 1000000 (inclusive) is: 607926 |
The number of square─free numbers between 1 and 1000000 (inclusive) is: 607926</pre> |
||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
Line 775: | Line 754: | ||
1000000000122 1000000000123 1000000000126 1000000000127 1000000000129 |
1000000000122 1000000000123 1000000000126 1000000000127 1000000000129 |
||
1000000000130 1000000000133 1000000000135 1000000000137 1000000000138 |
1000000000130 1000000000133 1000000000135 1000000000137 1000000000138 |
||
1000000000139 1000000000141 1000000000142 1000000000145 |
1000000000139 1000000000141 1000000000142 1000000000145</pre> |
||
</pre> |
|||
<lang zkl>n:=100; do(5){ |
<lang zkl>n:=100; do(5){ |
||
Line 784: | Line 762: | ||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
608 square-free integers from 1 to 1,000 |
608 square-free integers from 1 to 1,000 |
||
6,083 square-free integers from 1 to 10,000 |
6,083 square-free integers from 1 to 10,000 |
||
60,794 square-free integers from 1 to 100,000 |
60,794 square-free integers from 1 to 100,000 |
||
607,926 square-free integers from 1 to 1,000,000 |
607,926 square-free integers from 1 to 1,000,000</pre> |
||
</pre> |