結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
22,220 KB
testcase_01 AC 243 ms
22,088 KB
testcase_02 AC 239 ms
22,212 KB
testcase_03 AC 241 ms
22,008 KB
testcase_04 AC 239 ms
21,920 KB
testcase_05 AC 239 ms
22,208 KB
testcase_06 AC 241 ms
21,892 KB
testcase_07 AC 242 ms
21,920 KB
testcase_08 AC 240 ms
21,992 KB
testcase_09 AC 242 ms
22,060 KB
testcase_10 AC 242 ms
22,024 KB
testcase_11 AC 242 ms
22,212 KB
testcase_12 AC 239 ms
22,080 KB
testcase_13 AC 243 ms
22,092 KB
testcase_14 AC 243 ms
22,008 KB
testcase_15 AC 240 ms
21,784 KB
testcase_16 AC 241 ms
22,200 KB
testcase_17 AC 244 ms
22,036 KB
testcase_18 AC 245 ms
21,996 KB
testcase_19 AC 242 ms
22,080 KB
testcase_20 AC 242 ms
21,836 KB
testcase_21 AC 254 ms
22,060 KB
testcase_22 AC 251 ms
22,028 KB
testcase_23 AC 240 ms
21,984 KB
testcase_24 AC 242 ms
22,092 KB
testcase_25 AC 276 ms
22,044 KB
testcase_26 AC 261 ms
21,840 KB
testcase_27 AC 243 ms
22,104 KB
testcase_28 AC 245 ms
21,892 KB
testcase_29 AC 249 ms
22,064 KB
testcase_30 AC 248 ms
22,208 KB
testcase_31 AC 254 ms
22,232 KB
testcase_32 AC 264 ms
22,224 KB
testcase_33 AC 264 ms
22,264 KB
testcase_34 AC 263 ms
22,252 KB
testcase_35 AC 256 ms
22,128 KB
testcase_36 AC 256 ms
21,976 KB
testcase_37 AC 245 ms
22,108 KB
testcase_38 AC 243 ms
22,036 KB
testcase_39 AC 259 ms
22,028 KB
testcase_40 AC 258 ms
22,012 KB
testcase_41 AC 259 ms
21,880 KB
testcase_42 AC 255 ms
21,992 KB
testcase_43 AC 250 ms
22,164 KB
testcase_44 AC 247 ms
22,044 KB
testcase_45 AC 242 ms
22,192 KB
testcase_46 AC 244 ms
21,980 KB
testcase_47 AC 246 ms
21,836 KB
testcase_48 AC 278 ms
22,020 KB
testcase_49 AC 278 ms
21,896 KB
testcase_50 AC 251 ms
21,984 KB
testcase_51 AC 256 ms
22,116 KB
testcase_52 AC 244 ms
21,920 KB
testcase_53 AC 378 ms
22,216 KB
testcase_54 TLE -
testcase_55 TLE -
testcase_56 TLE -
testcase_57 AC 723 ms
21,896 KB
testcase_58 AC 713 ms
22,016 KB
testcase_59 AC 392 ms
22,032 KB
testcase_60 AC 992 ms
21,832 KB
testcase_61 AC 1,002 ms
22,100 KB
testcase_62 TLE -
testcase_63 AC 1,742 ms
22,320 KB
testcase_64 AC 1,335 ms
21,980 KB
testcase_65 AC 1,236 ms
21,792 KB
testcase_66 AC 241 ms
21,864 KB
testcase_67 AC 239 ms
22,200 KB
testcase_68 TLE -
testcase_69 TLE -
testcase_70 TLE -
testcase_71 TLE -
testcase_72 AC 1,656 ms
22,312 KB
testcase_73 TLE -
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, 400000)
initCnts(cnts, 400000)

ans = 0
max_exist = 0
i = 0
while primes[i] <= n do
	j = i + 1
	while primes[j] - primes[i] <= max_exist do
		ans += cnts[primes[j] - primes[i]]
		j += 1
	end
	
	j = 0
	while j < i do
		cnts[primes[j] + primes[i]] += 1
		j += 1
	end
	
	if (i > 0) then
		max_exist = primes[i] + primes[i - 1]
	end
	
	i += 1
end

puts(ans)
0