interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

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}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text sp " "
8text lo "square-free integers from 1 to 145:"
9text hi "square-free integers from 1000000000000 to 1000000000145:"
10text upto "square-free integers up to "
11text col ": "
12note cp marks composites below 10^6 (a prime sieve); sq n becomes 1 when some p^2 divides n, n <= 10^6;
13note wn marks the window 10^12 .. 10^12 + 145 the same way. Any square factor of a number up to
14note 10^12 + 145 has a prime p <= 10^6 + 1 (p^2 > 10^12 + 145 otherwise), and 10^6 + 1 = 101 * 9901 is composite
15global cp uchar 1000001
16global sq uchar 1000001
17note emit writes every byte of a to stdout; a short write is retried, an error exits 1
18fn emit a view uchar * to void
19o = ulong 0
20while lt o len a bound 4096
21k = write 1 a o sub len a o
22if le k 0
23exit 1
24end
25o = add o ulong k
26end
27end
28note emitu writes n in decimal; 20 digits hold every ulong
29fn emitu n ulong to void
30d = new uchar 20 0
31i = ulong 20
32v = n
33while true bound 20
34i = sub i 1
35put d i uchar add rem v 10 48
36v = div v 10
37if eq v 0
38break
39end
40end
41emit part d i sub 20 i
42end
43fn main to int
44wn = new uchar 146 0
45base = ulong 1000000000000
46p = ulong 2
47while le p 1000000 bound 999999
48if eq get cp p 0
49if le mul p p 1000000
50j = mul p p
51while le j 1000000 bound 999999
52put cp j 1
53j = add j p
54end
55end
56q = mul p p
57j = q
58while le j 1000000 bound 999999
59put sq j 1
60j = add j q
61end
62r = rem base q
63j = ulong 0
64if gt r 0
65j = sub q r
66end
67while le j 145 bound 146
68put wn j 1
69j = add j q
70end
71end
72p = add p 1
73end
74emit lo
75for i ulong 145
76if eq get sq add i 1 0
77emit sp
78emitu add i 1
79end
80end
81emit nl
82emit hi
83for i ulong 146
84if eq get wn i 0
85emit sp
86emitu add base i
87end
88end
89emit nl
90c = ulong 0
91lim = ulong 100
92for i ulong 1000000
93n = add i 1
94if eq get sq n 0
95c = add c 1
96end
97if eq n lim
98emit upto
99emitu lim
100emit col
101emitu c
102emit nl
103lim = mul lim 10
104end
105end
106ret 0
107end
108</syntaxhighlight>
109{{out}}
110<pre>
111square-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
112square-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
113square-free integers up to 100: 61
114square-free integers up to 1000: 608
115square-free integers up to 10000: 6083
116square-free integers up to 100000: 60794
117square-free integers up to 1000000: 607926
118</pre>