結果

問題 No.278 連続する整数の和(2)
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-13 12:42:03
言語 Python2
(2.7.18)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 911 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 51,252 KB
最終ジャッジ日時 2024-04-26 21:31:08
合計ジャッジ時間 11,954 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 524 ms
50,992 KB
testcase_01 AC 516 ms
51,252 KB
testcase_02 AC 580 ms
50,868 KB
testcase_03 AC 511 ms
50,864 KB
testcase_04 AC 556 ms
50,740 KB
testcase_05 AC 552 ms
50,740 KB
testcase_06 AC 508 ms
50,736 KB
testcase_07 AC 563 ms
50,744 KB
testcase_08 AC 567 ms
50,740 KB
testcase_09 AC 502 ms
50,736 KB
testcase_10 AC 567 ms
50,868 KB
testcase_11 AC 576 ms
50,864 KB
testcase_12 AC 500 ms
51,176 KB
testcase_13 AC 567 ms
50,868 KB
testcase_14 AC 577 ms
50,868 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 577 ms
50,868 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