結果
| 問題 | 
                            No.864 四方演算
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-09-22 17:34:28 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 51 ms / 1,000 ms | 
| コード長 | 1,404 bytes | 
| コンパイル時間 | 367 ms | 
| コンパイル使用メモリ | 82,576 KB | 
| 実行使用メモリ | 61,716 KB | 
| 最終ジャッジ日時 | 2024-07-05 08:35:00 | 
| 合計ジャッジ時間 | 2,665 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
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)