結果

問題 No.732 3PrimeCounting
ユーザー startcppstartcpp
提出日時 2017-01-22 15:20:46
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 903 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 11,252 KB
実行使用メモリ 22,460 KB
最終ジャッジ日時 2023-08-24 20:00:16
合計ジャッジ時間 11,764 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
22,460 KB
testcase_01 AC 83 ms
15,152 KB
testcase_02 AC 78 ms
15,156 KB
testcase_03 AC 78 ms
15,300 KB
testcase_04 AC 78 ms
15,296 KB
testcase_05 AC 78 ms
15,128 KB
testcase_06 AC 77 ms
15,296 KB
testcase_07 AC 78 ms
15,344 KB
testcase_08 AC 78 ms
15,136 KB
testcase_09 AC 77 ms
15,092 KB
testcase_10 AC 79 ms
15,092 KB
testcase_11 AC 78 ms
15,292 KB
testcase_12 AC 78 ms
15,340 KB
testcase_13 AC 79 ms
15,140 KB
testcase_14 AC 79 ms
15,160 KB
testcase_15 AC 77 ms
15,256 KB
testcase_16 AC 77 ms
15,088 KB
testcase_17 AC 77 ms
15,236 KB
testcase_18 AC 77 ms
15,260 KB
testcase_19 AC 77 ms
15,168 KB
testcase_20 AC 81 ms
15,048 KB
testcase_21 AC 109 ms
15,560 KB
testcase_22 AC 110 ms
15,296 KB
testcase_23 AC 77 ms
15,140 KB
testcase_24 AC 79 ms
15,292 KB
testcase_25 AC 179 ms
15,412 KB
testcase_26 AC 137 ms
15,432 KB
testcase_27 AC 85 ms
15,092 KB
testcase_28 AC 84 ms
15,044 KB
testcase_29 AC 102 ms
15,228 KB
testcase_30 AC 100 ms
15,320 KB
testcase_31 AC 116 ms
15,600 KB
testcase_32 AC 149 ms
15,512 KB
testcase_33 AC 152 ms
15,548 KB
testcase_34 AC 153 ms
15,516 KB
testcase_35 AC 123 ms
15,372 KB
testcase_36 AC 123 ms
15,596 KB
testcase_37 AC 82 ms
15,140 KB
testcase_38 AC 79 ms
15,128 KB
testcase_39 AC 126 ms
15,548 KB
testcase_40 AC 119 ms
15,392 KB
testcase_41 AC 121 ms
15,296 KB
testcase_42 AC 118 ms
15,416 KB
testcase_43 AC 105 ms
15,416 KB
testcase_44 AC 104 ms
15,160 KB
testcase_45 AC 87 ms
15,220 KB
testcase_46 AC 86 ms
15,040 KB
testcase_47 AC 92 ms
15,296 KB
testcase_48 AC 194 ms
15,380 KB
testcase_49 AC 193 ms
15,300 KB
testcase_50 AC 111 ms
15,308 KB
testcase_51 AC 113 ms
15,496 KB
testcase_52 AC 87 ms
15,092 KB
testcase_53 AC 461 ms
15,828 KB
testcase_54 TLE -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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