結果
問題 |
No.732 3PrimeCounting
|
ユーザー |
![]() |
提出日時 | 2017-01-22 15:37:45 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 920 bytes |
コンパイル時間 | 95 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 45,312 KB |
最終ジャッジ日時 | 2024-12-23 05:38:02 |
合計ジャッジ時間 | 102,432 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 71 TLE * 18 |
コンパイルメッセージ
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
ソースコード
#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)