Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/square-free-integers.wiki # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / drafts / rosettacode / square-free-integers.wiki` 118 lines ยท 3920 bytes Raw Blame History 1 =={{header|Omegese}}== 2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}} 3 Omega has no imports, so the small output helpers (emit and friends) are part of the program. 4 5 om2 6 text nl "\n" 7 text sp " " 8 text lo "square-free integers from 1 to 145:" 9 text hi "square-free integers from `1000000000000` to `1000000000145`:" 10 text upto "square-free integers up to " 11 text col ": " 12 note cp marks composites below 10^6 (a prime sieve); sq n becomes 1 when some p^2 divides n, n <= 10^6; 13 note wn marks the window 10^12 .. 10^12 + 145 the same way. Any square factor of a number up to 14 note 10^12 + 145 has a prime p <= 10^6 + 1 (p^2 > 10^12 + 145 otherwise), and 10^6 + 1 = 101 * 9901 is composite 15 global cp uchar `1000001` 16 global sq uchar `1000001` 17 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 18 fn emit a view uchar * to void 19 o = ulong 0 20 while lt o len a bound 4096 21 k = write 1 a o sub len a o 22 if le k 0 23 exit 1 24 end 25 o = add o ulong k 26 end 27 end 28 note emitu writes n in decimal; 20 digits hold every ulong 29 fn emitu n ulong to void 30 d = new uchar 20 0 31 i = ulong 20 32 v = n 33 while true bound 20 34 i = sub i 1 35 put d i uchar add rem v 10 48 36 v = div v 10 37 if eq v 0 38 break 39 end 40 end 41 emit part d i sub 20 i 42 end 43 fn main to int 44 wn = new uchar 146 0 45 base = ulong `1000000000000` 46 p = ulong 2 47 while le p `1000000` bound 999999 48 if eq get cp p 0 49 if le mul p p `1000000` 50 j = mul p p 51 while le j `1000000` bound 999999 52 put cp j 1 53 j = add j p 54 end 55 end 56 q = mul p p 57 j = q 58 while le j `1000000` bound 999999 59 put sq j 1 60 j = add j q 61 end 62 r = rem base q 63 j = ulong 0 64 if gt r 0 65 j = sub q r 66 end 67 while le j 145 bound 146 68 put wn j 1 69 j = add j q 70 end 71 end 72 p = add p 1 73 end 74 emit lo 75 for i ulong 145 76 if eq get sq add i 1 0 77 emit sp 78 emitu add i 1 79 end 80 end 81 emit nl 82 emit hi 83 for i ulong 146 84 if eq get wn i 0 85 emit sp 86 emitu add base i 87 end 88 end 89 emit nl 90 c = ulong 0 91 lim = ulong 100 92 for i ulong `1000000` 93 n = add i 1 94 if eq get sq n 0 95 c = add c 1 96 end 97 if eq n lim 98 emit upto 99 emitu lim 100 emit col 101 emitu c 102 emit nl 103 lim = mul lim 10 104 end 105 end 106 ret 0 107 end 108 109 {{out}} 110

111 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

112 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`

113 square-free integers up to 100: 61

114 square-free integers up to 1000: 608

115 square-free integers up to 10000: 6083

116 square-free integers up to 100000: 60794

117 square-free integers up to `1000000`: 607926

118