結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-14 16:48:01
言語 Python2
(2.7.18)
結果
AC  
実行時間 219 ms / 1,000 ms
コード長 1,008 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 6,568 KB
実行使用メモリ 9,988 KB
最終ジャッジ日時 2023-08-29 00:59:20
合計ジャッジ時間 3,936 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
8,052 KB
testcase_01 AC 34 ms
8,196 KB
testcase_02 AC 34 ms
8,056 KB
testcase_03 AC 34 ms
8,196 KB
testcase_04 AC 33 ms
8,092 KB
testcase_05 AC 33 ms
8,092 KB
testcase_06 AC 33 ms
8,060 KB
testcase_07 AC 33 ms
8,236 KB
testcase_08 AC 34 ms
8,244 KB
testcase_09 AC 33 ms
8,144 KB
testcase_10 AC 33 ms
8,056 KB
testcase_11 AC 33 ms
8,080 KB
testcase_12 AC 33 ms
8,240 KB
testcase_13 AC 33 ms
8,248 KB
testcase_14 AC 33 ms
8,240 KB
testcase_15 AC 33 ms
8,136 KB
testcase_16 AC 33 ms
8,252 KB
testcase_17 AC 34 ms
8,080 KB
testcase_18 AC 33 ms
8,236 KB
testcase_19 AC 34 ms
8,088 KB
testcase_20 AC 34 ms
8,156 KB
testcase_21 AC 34 ms
8,136 KB
testcase_22 AC 36 ms
8,140 KB
testcase_23 AC 35 ms
8,056 KB
testcase_24 AC 42 ms
8,244 KB
testcase_25 AC 45 ms
9,988 KB
testcase_26 AC 37 ms
8,136 KB
testcase_27 AC 34 ms
8,240 KB
testcase_28 AC 44 ms
8,080 KB
testcase_29 AC 219 ms
8,144 KB
testcase_30 AC 48 ms
8,056 KB
testcase_31 AC 57 ms
8,132 KB
testcase_32 AC 52 ms
8,240 KB
testcase_33 AC 53 ms
8,504 KB
testcase_34 AC 66 ms
8,172 KB
testcase_35 AC 63 ms
8,176 KB
testcase_36 AC 50 ms
8,240 KB
testcase_37 AC 51 ms
8,176 KB
testcase_38 AC 48 ms
8,244 KB
testcase_39 AC 45 ms
8,244 KB
testcase_40 AC 48 ms
8,248 KB
testcase_41 AC 38 ms
8,324 KB
testcase_42 AC 36 ms
8,664 KB
testcase_43 AC 83 ms
8,136 KB
testcase_44 AC 42 ms
8,244 KB
testcase_45 AC 33 ms
8,136 KB
権限があれば一括ダウンロードができます

ソースコード

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):
    #print p
    if H/p < p:
        continue
    for c in range((H/p)*p, L-1, -p):
        if c==p:
            break
        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