結果

問題 No.864 四方演算
ユーザー LyricalMaestro
提出日時 2025-01-14 00:56:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 718 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 82,644 KB
実行使用メモリ 60,032 KB
最終ジャッジ日時 2025-01-14 00:57:01
合計ジャッジ時間 3,589 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/864 

import math

def solve1(N, p):
    min_a1 = 1
    max_a1 = N

    min_a2 = p - N
    max_a2 = p - 1

    min_a = max(min_a1, min_a2)
    max_a = min(max_a1, max_a2)
    return max(0, max_a - min_a + 1)


def solve(N, p, q):
    a1 = solve1(N, p)
    a2 = solve1(N, q)
    return a1 * a2



def main():
    N = int(input())
    K = int(input())

    answer = 0
    sqrt_k = int(math.sqrt(K))
    for p in range(1, sqrt_k + 1):
        if K % p == 0:
            q = K // p
            a1 = solve(N, p, q)
            answer += a1
            if q != p:
                a2 = solve(N, q, p)
                answer += a2

    print(answer)



if __name__ == "__main__":
    main()
0