結果
| 問題 |
No.278 連続する整数の和(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-11-25 17:17:52 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 241 ms / 2,000 ms |
| コード長 | 1,641 bytes |
| コンパイル時間 | 154 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-10-02 00:16:03 |
| 合計ジャッジ時間 | 1,983 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
from itertools import count
from math import prod
def calc_positive_divisors(num: int) -> list[int]:
small_divisors = []
large_divisors = []
for n in range(1, floor(sqrt(num))+1):
if num % n == 0:
small_divisors.append(n)
large_divisors.append(num//n)
if small_divisors[-1] == large_divisors[-1]:
large_divisors.pop()
divisors = small_divisors + reversed(large_divisors)
return divisors
def calc_prime_factorize(num: int) -> dict[int, int]:
if num < 2:
raise ValueError
divisors = {}
for divisor in count(2):
if divisor ** 2 > num:
if num != 1:
divisors[num] = 1
break
while num % divisor == 0 and num != 1:
try:
divisors[divisor] += 1
except KeyError:
divisors[divisor] = 1
num //= divisor
return divisors
def gcd(*numbers: int) -> int:
if len(numbers) == 1:
return numbers[0]
if len(numbers) == 2:
a, b = numbers
if a < b:
a, b = b, a
while True:
if a % b == 0:
return b
a, b = b, a % b
first_gcd = gcd(*numbers[:2])
return gcd(first_gcd, *numbers[2:])
def main():
N = int(input())
if N == 1:
print(1)
return
max_X = gcd(N, (N-1)*N//2)
if max_X == 1:
print(1)
return
factors = calc_prime_factorize(max_X)
print(prod(sum(factor ** pow_ for pow_ in range(number+1))
for factor, number in factors.items()))
if __name__ == "__main__":
main()