#rubyの引数, 代入は参照渡し. 参照透明性とは何だったのか… def setPrime (is_prime, primes, n) for i in 2..n do is_prime[i] = true end for i in 2..n do if is_prime[i] then j = 2 * i while j <= n do is_prime[j] = false j += i end end end for i in 2..n do if is_prime[i] then primes.push(i); end end end def initCnts (cnts, n) for i in 0..n do cnts[i] = 0 end end #ここからmain n = STDIN.gets.chop.to_i is_prime = Array.new primes = Array.new cnts = Array.new setPrime(is_prime, primes, 3 * n) initCnts(cnts, 3 * n) rprimes = primes.reverse #primesの中身は変更されない ans = 0 for c in primes do if (c > n) then break end for sum in rprimes do if sum <= c then break end ans += cnts[sum - c] end for a in primes do if a >= c then break end cnts[a + c] += 1 end end puts(ans)