結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-14 16:38:14
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 961 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 7,076 KB
実行使用メモリ 15,420 KB
最終ジャッジ日時 2024-04-15 21:29:47
合計ジャッジ時間 7,059 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
15,420 KB
testcase_01 AC 36 ms
8,352 KB
testcase_02 AC 36 ms
8,476 KB
testcase_03 AC 35 ms
8,480 KB
testcase_04 AC 35 ms
8,480 KB
testcase_05 AC 36 ms
8,480 KB
testcase_06 AC 35 ms
8,476 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 35 ms
8,476 KB
testcase_10 AC 35 ms
8,476 KB
testcase_11 WA -
testcase_12 AC 36 ms
8,480 KB
testcase_13 AC 38 ms
8,432 KB
testcase_14 AC 37 ms
8,348 KB
testcase_15 WA -
testcase_16 AC 35 ms
8,352 KB
testcase_17 AC 36 ms
8,480 KB
testcase_18 AC 35 ms
8,480 KB
testcase_19 AC 35 ms
8,476 KB
testcase_20 WA -
testcase_21 AC 211 ms
8,352 KB
testcase_22 TLE -
testcase_23 AC 166 ms
8,608 KB
testcase_24 AC 45 ms
8,480 KB
testcase_25 AC 48 ms
10,420 KB
testcase_26 AC 40 ms
8,352 KB
testcase_27 AC 35 ms
8,604 KB
testcase_28 AC 53 ms
8,476 KB
testcase_29 AC 633 ms
8,476 KB
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
L,H=map(int,raw_input().split())

upperBound = 100001
isPrime=[True for i in range((upperBound-3)/2+1)]
for i in range((int(math.sqrt(upperBound-3))-3)/2+1): # k*k = (2i+3)^2 <= upperBound-3 
   if isPrime[i]:
      k = i+i+3 # this is prime number
      # false out non_prime number from k*k
      # k*k = 4i^2+12i+9 = 2*(2i^2+6i+3)+3
      # k*(k+1) = 2*(2i^2+6i+3)+3 + 2i+3 ... even number. skip
      # k*(k+2) = 2*(2i^2+6i+3+k)+3 
      non_prime = k*(i+1)+i
      for j in range(non_prime,(upperBound-3)/2+1,k):
         isPrime[j]=False
primes = [2] + [i+i+3 for i in range((upperBound-3)/2+1) if isPrime[i]==True]

primes.reverse()
for i,p in enumerate(primes):
    if H/p <= 1:
        continue
    for c in range((H/p)*p, L-1, -p):
        ok = True
        for j in range(i+1,len(primes)):
            q=primes[j]
            if c%q==0:
                ok=False
                break
        if ok:
            print c
            exit()
0