Jump to content

Blum integer: Difference between revisions

→‎{{header|Wren}}: Optimized - about 30% faster than before.
(→‎{{header|C}}: Specialized primeFactors routine - about 20% faster than before.)
(→‎{{header|Wren}}: Optimized - about 30% faster than before.)
Line 158:
import "./fmt" for Fmt
 
var bluminc = [4, 2, 4, 2, 4, 6, 2, 6]
 
// Assumes n is odd.
var firstPrimeFactor = Fn.new { |n|
if (n == 1) return 1
if (n%3 == 0) return 3
if (n%5 == 0) return 5
var k = 7
var i = 0
while (k * k <= n) {
if (n%k == 0) return{
return k
} else {
k = k + inc[i]
i = (i + 1) % 8
}
}
return n
}
 
var blum = List.filled(50, 0)
var bc = 0
var counts = { 1: 0, 3: 0, 7: 0, 9: 0 }
var i = 1
while (true) {
var fp = IntfirstPrimeFactor.primeFactorscall(i)
if (f.count == 2 && f[0] != f[1] && f[0] % 4 == 3 && f[1]p % 4 == 3) {
ifvar (bcq <= 50) blum.add(i) / p
counts[iif % 10](q != counts[ip && q % 10]4 == 3 && +Int.isPrime(q)) 1{
if (bc =< 50) blum[bc] += 1i
if (bc counts[i % 10] == 50)counts[i % 10] + {1
System.print("Firstbc 50= Blumbc integers:")+ 1
Fmt.tprintif ("$3dbc ",== blum, 1050) {
System.print("First 50 Blum integers:")
} else if (bc == 26828 || bc %Fmt.tprint("$3d 1e5", ==blum, 010) {
Fmt.print("The $,9r Blum integer is: $,9d", bc, iSystem.print()
} else if (bc == 40000026828 || bc % 1e5 == 0) {
SystemFmt.print("\n\%The distribution$,9r ofBlum theinteger firstis: 400$,9d",000 Blumbc, integers:"i)
forif (jbc in== [1, 3, 7, 9]400000) {
FmtSystem.print(" $6.3f\n\% enddistribution inof $d",the first counts[j]/4000400,000 jBlum integers:")
for (i in [1, 3, 7, 9]) {
Fmt.print(" $6.3f\% end in $d", counts[i]/4000, i)
}
return
}
return
}
}
Line 201 ⟶ 224:
The 400,000th Blum integer is: 8,802,377
 
% distribution of the first 400,000 Blum integers is:
25.001% end in 1
25.017% end in 3
24.997% end in 7
24.985% end in 9
</pre>
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.