java - sum(1/prime[i]^2) >= 1? -



java - sum(1/prime[i]^2) >= 1? -

while trying devise algorithm, stumbled upon question. it's not homework.

let p_i = array of first primes. need smallest i such that

sum<n=0..i> 1 / (p_i[n]*p_i[n]) >= 1.

(if such i exists).

an approximation i'th prime i*log(i). tried in java:

public static viod main(string args[]) { double sum = 0.0; long = 2; while(sum<1.0) { sum += 1.0 / (i*math.log(i)*i*math.log(i)); i++; } system.out.println(i+": "+sum); }

however above doesn't finish because converges 0.7. 1/100000000^2 rounds 0.0 in java, that's why doesn't work. same reason doesn't work if replace 6th line with

sum += 1.0 / (i*i)

while should reach 1 if i'm not mistaken, because sum should incease faster 1/2^i , latter converges 1. in other words, shows java rounding causes sum not reach 1. think minimum i of problem should exist.

on maths side of question, not java side:

if understand problem, there no solution (no value of i).

for finite set p_i of primes {p_1, p_2,...p_i} allow n_i set of integers p_i, {1,2,3,...,p_i}. sum 1/p^2 (for p_n in p_i) less sum of 1/x^2 x in n_i.

the sum of 1/x^2 tends ~1.65 since 1 never in set of primes, sum limited ~0.65

java algorithm math primes rounding

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -