結果

問題 No.864 四方演算
ユーザー kawacchukawacchu
提出日時 2019-08-16 22:21:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 771 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 81,720 KB
実行使用メモリ 80,144 KB
最終ジャッジ日時 2023-10-24 00:52:58
合計ジャッジ時間 2,719 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,516 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def trial_division(n):
    a = []  
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2   
    if n != 1: a.append(n)
    return a

N = int(input())
K = int(input())

T = trial_division(K)
D = {0:1}
ans = 0

for bit in range(1 << len(T)) :
    A = 1
    B = 1
    for k in range(len(T)) :
        if bit & (1 << k) :
            A *= T[k]
        else :
            B *= T[k]
    if A in D : continue
    D[A] = 1
    cnt1 = 0
    cnt2 = 0
    for a in range(1,N+1) :
        if 1 <= A-a <= N :
            cnt1 += 1
    for b in range(1,N+1) :
        if 1 <= B-b <= N :
            cnt2 += 1
    ans += (cnt1*cnt2)
    
print(ans)
0