結果

問題 No.732 3PrimeCounting
ユーザー startcpp
提出日時 2017-01-22 15:20:46
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 903 bytes
コンパイル時間 57 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 29,824 KB
最終ジャッジ日時 2024-12-23 05:32:24
合計ジャッジ時間 114,017 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 66 TLE * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:3: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
Main.rb:25: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
Syntax OK

ソースコード

diff #

#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)
0