結果

問題 No.864 四方演算
ユーザー kawacchukawacchu
提出日時 2019-08-16 22:38:36
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 873 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 79,896 KB
最終ジャッジ日時 2023-10-26 02:47:38
合計ジャッジ時間 3,091 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,616 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

    if A <= N :
        cnt1 = A-1
    elif N < A <= 2*N :
        cnt1 = N-(A-N)+1
    else :
        cnt1 = 0
    
    if B <= N :
        cnt2 = B-1
    elif N < B <= 2*N :
        cnt2 = N-(B-N)+1
    else :
        cnt2 = 0
    #print(A,B,cnt1,cnt2)
    ans += (cnt1*cnt2)
    
print(ans)
0