結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-14 16:38:14
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 961 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 6,592 KB
実行使用メモリ 9,956 KB
最終ジャッジ日時 2023-07-28 12:45:13
合計ジャッジ時間 7,650 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
8,092 KB
testcase_01 AC 33 ms
8,064 KB
testcase_02 AC 33 ms
7,988 KB
testcase_03 AC 34 ms
8,040 KB
testcase_04 AC 34 ms
8,088 KB
testcase_05 AC 34 ms
8,068 KB
testcase_06 AC 34 ms
8,120 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 36 ms
8,084 KB
testcase_10 AC 34 ms
8,168 KB
testcase_11 WA -
testcase_12 AC 33 ms
8,056 KB
testcase_13 AC 35 ms
8,132 KB
testcase_14 AC 34 ms
8,064 KB
testcase_15 WA -
testcase_16 AC 34 ms
8,056 KB
testcase_17 AC 33 ms
8,052 KB
testcase_18 AC 33 ms
8,112 KB
testcase_19 AC 33 ms
8,084 KB
testcase_20 WA -
testcase_21 AC 195 ms
8,040 KB
testcase_22 TLE -
testcase_23 AC 153 ms
8,104 KB
testcase_24 AC 42 ms
8,040 KB
testcase_25 AC 45 ms
9,956 KB
testcase_26 AC 37 ms
8,128 KB
testcase_27 AC 33 ms
8,108 KB
testcase_28 AC 50 ms
8,128 KB
testcase_29 AC 584 ms
8,084 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