-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.sf
22 lines (17 loc) · 1.05 KB
/
prog.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/ruby
# Number of odd semiprimes less than 2^n.
# https://oeis.org/A362042
# Terms:
# 0, 0, 0, 0, 2, 4, 11, 24, 51, 103, 207, 417, 815, 1622, 3164, 6210, 12146, 23711, 46295, 90307, 176369, 344155, 672091, 1312721, 2565048, 5013566, 9804910, 19183069, 37547164, 73526846, 144042323, 282317826, 553564500, 1085869406, 2130916524, 4183381508, 8215884036, 16141427963, 31723866361, 62370738996, 122665338058, 241325794755, 474921367858, 934913584263, 1840977104092, 3626171491221, 7144421771451, 14079941975945, 27755296183385, 54726597576934, 107933230558886, 212918183021710, 420114808112636, 829120908511644, 1636663786905232, 3231394736936333, 6381265628131569, 12603969451816191, 24899413334814548, 49198265137944157, 97227049414548237, 192175889896107844, 379912070399250915, 751169045016870577
func odd_semiprime_count(n) is cached {
n.semiprime_count - idiv(n,2).pi
}
with (1e6.irand) {|n|
assert_eq(
n.semiprimes.count{.is_odd},
odd_semiprime_count(n)
)
}
for n in (0 .. 1e6) {
print(odd_semiprime_count(2**n), ", ")
}