結果

問題 No.278 連続する整数の和(2)
ユーザー mkawa2mkawa2
提出日時 2020-01-31 20:48:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 1,531 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 12,052 KB
実行使用メモリ 10,340 KB
最終ジャッジ日時 2023-10-17 08:29:53
合計ジャッジ時間 1,782 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,340 KB
testcase_01 AC 33 ms
10,340 KB
testcase_02 AC 117 ms
10,340 KB
testcase_03 AC 33 ms
10,340 KB
testcase_04 AC 31 ms
10,340 KB
testcase_05 AC 31 ms
10,340 KB
testcase_06 AC 32 ms
10,340 KB
testcase_07 AC 32 ms
10,340 KB
testcase_08 AC 31 ms
10,340 KB
testcase_09 AC 32 ms
10,340 KB
testcase_10 AC 32 ms
10,340 KB
testcase_11 AC 41 ms
10,340 KB
testcase_12 AC 32 ms
10,340 KB
testcase_13 AC 91 ms
10,340 KB
testcase_14 AC 37 ms
10,340 KB
testcase_15 AC 64 ms
10,340 KB
testcase_16 AC 39 ms
10,340 KB
testcase_17 AC 38 ms
10,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# (底,指数)を返す
# 18=2**1 * 3**2なので[(2,1),(3,2)]
def PrimeFactorization(x):
    def plist(x):
        if x < 2: return []
        if x & 1 == 0: return [2] + plist(x // 2)
        for p in range(3, x + 1, 2):
            if x % p == 0: return [p] + plist(x // p)
            if p ** 2 > x: return [x]

    pl = plist(x)
    pp, ee = [], []
    for p in pl:
        if not pp or p != pp[-1]:
            pp += [p]
            ee += [0]
        ee[-1] += 1
    return [(p, e) for p, e in zip(pp, ee)]

def gcd(a, b):
    while b: a, b = b, a % b
    return a

def expsum(p, e):
    return (pow(p, e + 1) - 1) // (p - 1)

def main():
    n = II()
    c = (n - 1) * n // 2
    g = gcd(n, c)
    ans = 1
    for p, e in PrimeFactorization(g):
        ans *= expsum(p, e)
    print(ans)

main()
0