結果

問題 No.639 An Ordinary Sequence
ユーザー coro65536coro65536
提出日時 2018-01-27 00:05:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 1,000 ms
コード長 1,073 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 10,808 KB
実行使用メモリ 8,472 KB
最終ジャッジ日時 2023-08-30 12:50:38
合計ジャッジ時間 1,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,452 KB
testcase_01 AC 17 ms
8,420 KB
testcase_02 AC 15 ms
8,272 KB
testcase_03 AC 16 ms
8,344 KB
testcase_04 AC 16 ms
8,284 KB
testcase_05 AC 16 ms
8,340 KB
testcase_06 AC 16 ms
8,368 KB
testcase_07 AC 16 ms
8,384 KB
testcase_08 AC 16 ms
8,276 KB
testcase_09 AC 16 ms
8,284 KB
testcase_10 AC 16 ms
8,460 KB
testcase_11 AC 16 ms
8,364 KB
testcase_12 AC 17 ms
8,424 KB
testcase_13 AC 17 ms
8,424 KB
testcase_14 AC 16 ms
8,416 KB
testcase_15 AC 17 ms
8,472 KB
testcase_16 AC 17 ms
8,284 KB
testcase_17 AC 16 ms
8,408 KB
testcase_18 AC 17 ms
8,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# C
import math
# import scipy.misc as scm

def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator

N = int(input())

if N == 0:
    print(1)
    quit()
if N == 1 or N == 2:
    print(2)
    quit()

arr = [[0 for j in range(int(math.log(N, 5))+1)] for i in range(int(math.log(N, 3))+1)]  # 1 indexed

ans = 2 + int(math.log(N, 5)) + int(math.log(N, 3))

for i in range(1, int(math.log(N, 3))+1):
    for j in range(1, int(math.log(N, 5))+1):
        if 3**i * 5**j <= N:
#            ans += scm.comb(i+j, i, 1)
            ans += nCr(i+j, i)

print(ans)

0