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/factors-of-an-integer.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 / factors-of-an-integer.wiki` 85 lines ยท 2056 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 pre "factors of " 9 text col ":" 10 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 11 fn emit a view uchar * to void 12 o = ulong 0 13 while lt o len a bound 4096 14 k = write 1 a o sub len a o 15 if le k 0 16 exit 1 17 end 18 o = add o ulong k 19 end 20 end 21 note emitu writes n in decimal; 20 digits hold every ulong 22 fn emitu n ulong to void 23 d = new uchar 20 0 24 i = ulong 20 25 v = n 26 while true bound 20 27 i = sub i 1 28 put d i uchar add rem v 10 48 29 v = div v 10 30 if eq v 0 31 break 32 end 33 end 34 emit part d i sub 20 i 35 end 36 note divisors d with d * d <= n come out ascending; their partners n / d, read back in reverse, finish the list 37 note bound: the largest n here is `600851475143`, so d stays below 775147, and no n has more than 64 small divisors 38 fn tell n ulong to void 39 lo = new ulong 64 0 40 k = ulong 0 41 d = ulong 1 42 while le mul d d n bound 999999 43 if eq rem n d 0 44 put lo k d 45 k = add k 1 46 end 47 d = add d 1 48 end 49 emit pre 50 emitu n 51 emit col 52 for i ulong k 53 emit sp 54 emitu get lo i 55 end 56 for i ulong k 57 e = get lo sub sub k 1 i 58 if ne mul e e n 59 emit sp 60 emitu div n e 61 end 62 end 63 emit nl 64 end 65 fn main to int 66 tell 1 67 tell 45 68 tell 53 69 tell 64 70 tell 720 71 tell `1000000` 72 tell `600851475143` 73 ret 0 74 end 75 76 {{out}} 77

78 factors of 1: 1

79 factors of 45: 1 3 5 9 15 45

80 factors of 53: 1 53

81 factors of 64: 1 2 4 8 16 32 64

82 factors of 720: 1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 30 36 40 45 48 60 72 80 90 120 144 180 240 360 720

83 factors of `1000000`: 1 2 4 5 8 10 16 20 25 32 40 50 64 80 100 125 160 200 250 320 400 500 625 800 1000 1250 1600 2000 2500 3125 4000 5000 6250 8000 10000 12500 15625 20000 25000 31250 40000 50000 62500 100000 125000 200000 250000 500000 `1000000`

84 factors of `600851475143`: 1 71 839 1471 6857 59569 104441 486847 `1234169` `5753023` `10086647` `87625999` `408464633` `716151937` `8462696833` `600851475143`

85