結果

問題 No.278 連続する整数の和(2)
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-13 12:42:03
言語 Python2
(2.7.18)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 911 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 7,100 KB
実行使用メモリ 50,724 KB
最終ジャッジ日時 2023-08-09 06:42:09
合計ジャッジ時間 12,140 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 484 ms
50,724 KB
testcase_01 AC 486 ms
50,616 KB
testcase_02 AC 547 ms
50,276 KB
testcase_03 AC 489 ms
50,320 KB
testcase_04 AC 540 ms
50,324 KB
testcase_05 AC 541 ms
50,320 KB
testcase_06 AC 487 ms
50,288 KB
testcase_07 AC 538 ms
50,288 KB
testcase_08 AC 544 ms
50,396 KB
testcase_09 AC 483 ms
50,360 KB
testcase_10 AC 541 ms
50,356 KB
testcase_11 AC 545 ms
50,304 KB
testcase_12 AC 482 ms
50,672 KB
testcase_13 AC 546 ms
50,400 KB
testcase_14 AC 543 ms
50,424 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 550 ms
50,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
N=int(raw_input())
M=N*(N-1)/2

upperBound = 2000001
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]
#print len(primes)

ans=1
for p in primes:
    if min(N,M) <= 1:
        break
    tmp=1
    while N%p==0 and M%p ==0:
        tmp*=p
        tmp+=1
        N/=p
        M/=p
    ans*=tmp
if min(N,M) > 1:
    p=min(N,M)
    if N%p==0 and M%p == 0:
        ans *= p+1

print ans
0