結果

問題 No.2358 xy+yz+zx=N
ユーザー FromBooskaFromBooska
提出日時 2023-06-24 13:47:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,037 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 86,784 KB
実行使用メモリ 91,288 KB
最終ジャッジ日時 2023-09-14 10:19:16
合計ジャッジ時間 4,808 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,360 KB
testcase_01 AC 73 ms
71,604 KB
testcase_02 AC 76 ms
75,440 KB
testcase_03 AC 73 ms
71,152 KB
testcase_04 AC 73 ms
71,268 KB
testcase_05 AC 72 ms
71,304 KB
testcase_06 AC 118 ms
76,492 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 10**7ということは1周しかできない、2重ループは不可
# 因数分解できる形に変形
# 相加相乗平均、二乗式への式変形
# 3項なら2項にして考察
# 0 <= x <= y <= z <= Nとして考える
# 真ん中全探索y決め打ち
# 1つを固定してあとは因数分解で決めるのでどうだ

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 = 0
ans_list = []
for z in range(0, N+1):
    # 因数分解形
    # (X+z)(Y+z) - z**2 = N
    # (X+z)(Y+z) = N+z**2
    divs = divisors(N+z**2)
    #print('z', z, 'divs', divs)
    for d1 in divs:
        d2 = (N+z**2)//d1
        if d1-z >= 0 and d2-z >= 0:
            ans += 1
            ans_list.append((d1-z, d2-z, z))
print(len(ans_list))
for X, Y, Z in ans_list:
    print(X, Y, Z)
0