結果

問題 No.2358 xy+yz+zx=N
ユーザー FromBooska
提出日時 2024-03-21 18:41:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 81,996 KB
実行使用メモリ 83,352 KB
最終ジャッジ日時 2024-09-30 10:12:01
合計ジャッジ時間 2,996 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

# 真ん中全探索か、2項の積の表を作るか、因数分解使うか、0を別に考えるか
# まず真ん中全探索、x<=y<=zとしてyが固定されれば因数分解で(y+z)(y+x)=N+y**2

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

N = int(input())

ans_set = set()
for y in range(0, N+1):
    if y**2 > N:
        break
    
    divs = divisors(N+y**2)
    for d1 in divs:
        if d1**2 > (N+y**2):
            break
        
        d2 = (N+y**2)//d1
        x = d1-y
        z = d2-y
        if x>=0 and z>=0:
            ans_set.add((x, y, z))
            ans_set.add((x, z, y))
            ans_set.add((y, x, z))
            ans_set.add((y, z, x))
            ans_set.add((z, x, y))
            ans_set.add((z, y, x))
            
print(len(ans_set))
for x, y, z in ans_set:
    print(x, y, z)



0