#rubyの引数, 代入は参照渡し. 参照透明性とは何だったのか… #このコードは定数倍が重いのでTLEします 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) ans = 0 for c in primes do if (c > n) then break end for sum in primes do if sum <= c then next 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)