結果

問題 No.278 連続する整数の和(2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-09-05 11:24:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 993 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-26 08:46:19
合計ジャッジ時間 2,325 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,604 KB
testcase_01 RE -
testcase_02 AC 147 ms
8,600 KB
testcase_03 AC 19 ms
8,748 KB
testcase_04 AC 19 ms
8,648 KB
testcase_05 AC 20 ms
8,708 KB
testcase_06 AC 19 ms
8,596 KB
testcase_07 AC 19 ms
8,640 KB
testcase_08 AC 19 ms
8,612 KB
testcase_09 AC 19 ms
8,712 KB
testcase_10 AC 21 ms
8,752 KB
testcase_11 AC 33 ms
8,708 KB
testcase_12 RE -
testcase_13 AC 103 ms
8,644 KB
testcase_14 AC 27 ms
8,748 KB
testcase_15 AC 66 ms
8,592 KB
testcase_16 AC 30 ms
8,752 KB
testcase_17 AC 27 ms
8,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import collections

def factorize(n):
    ''' returns a list of prime factors of n.
    ex. factorize(24) = [2, 2, 2, 3]
    source: Rossetta code: prime factorization (slightly modified)
    http://rosettacode.org/wiki/Prime_decomposition#Python:_Using_floating_point
    '''
    step = lambda x: 1 + (x<<2) - ((x>>1)<<1)
    maxq = int(math.floor(math.sqrt(n)))
    d = 1
    q = n % 2 == 0 and 2 or 3
    while q <= maxq and n % q != 0:
        q = step(d)
        d += 1
    return q <= maxq and [q] + factorize(n//q) or [n]

def sum_of_divisors(n):
    ''' returns the sum of divisors of integer n.
    n must be a positive integer.
    the sum includes n itself.
    ex. sum_of_divisors(6) = 6 + 3 + 2 + 1 = 12
    '''
    factors = collections.Counter(factorize(n))
    result = 1
    for p, a in factors.items():
        result *= (p ** (a + 1) - 1)//(p - 1)
    return result

N = int(input())
if N & 1:
    print(sum_of_divisors(N))
else:
    print(sum_of_divisors(N//2))
0