結果

問題 No.864 四方演算
ユーザー shinichishinichi
提出日時 2021-09-22 17:34:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 113 ms / 1,000 ms
コード長 1,404 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 76,896 KB
最終ジャッジ日時 2023-09-18 18:38:27
合計ジャッジ時間 5,423 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,824 KB
testcase_01 AC 113 ms
76,264 KB
testcase_02 AC 110 ms
76,532 KB
testcase_03 AC 109 ms
76,596 KB
testcase_04 AC 112 ms
76,488 KB
testcase_05 AC 107 ms
76,260 KB
testcase_06 AC 111 ms
76,524 KB
testcase_07 AC 110 ms
76,620 KB
testcase_08 AC 107 ms
76,384 KB
testcase_09 AC 102 ms
76,264 KB
testcase_10 AC 103 ms
76,484 KB
testcase_11 AC 100 ms
76,484 KB
testcase_12 AC 110 ms
76,632 KB
testcase_13 AC 106 ms
76,412 KB
testcase_14 AC 101 ms
76,560 KB
testcase_15 AC 113 ms
76,544 KB
testcase_16 AC 111 ms
76,536 KB
testcase_17 AC 113 ms
76,528 KB
testcase_18 AC 111 ms
76,896 KB
testcase_19 AC 106 ms
76,320 KB
testcase_20 AC 113 ms
76,656 KB
testcase_21 AC 110 ms
76,540 KB
testcase_22 AC 108 ms
76,516 KB
testcase_23 AC 97 ms
76,448 KB
testcase_24 AC 106 ms
76,504 KB
testcase_25 AC 101 ms
76,476 KB
testcase_26 AC 107 ms
76,568 KB
testcase_27 AC 91 ms
71,768 KB
testcase_28 AC 93 ms
71,504 KB
testcase_29 AC 93 ms
71,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter


def make_divisors(n):
    lower, upper = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)
        i += 1
    return lower + upper[::-1]

def prime_factorize(n):
    primes = []
    while not n % 2:
        primes.append(2)
        n //= 2
    while not n % 3:
        primes.append(3)
        n //= 3
    for p in range(5, int(n**0.5)+1, 6):
        while not n % p:
            primes.append(p)
            n //= p
        while not n % (p+2):
            primes.append(p+2)
            n //= (p+2)
    if n != 1:
        primes.append(n)
    return primes

# n以下の数でnと互いに素である数の個数
def euler_fanction(n):
    cnt = n
    for p in set(prime_factorize(n)):
        cnt *= p-1
        cnt //= p
    return cnt

# {prime1: cnt1, prime2: cnt2, ..}という辞書型で返す
def prime_factorize_count(n):
    primes = prime_factorize(n)
    return Counter(primes)


if __name__ == '__main__':
    N = int(input())
    K = int(input())
    divisors = make_divisors(K)
    ans = 0
    for a in divisors:
        b = K // a
        aa, bb = a-1, b-1
        if 2 * N < a or 2 * N < b:
            continue
        if a > N:
            aa -= (a-N-1) * 2
        if b > N:
            bb -= (b-N-1) * 2
        ans += aa * bb
    print(ans)
0