結果
問題 | No.2358 xy+yz+zx=N |
ユーザー | FromBooska |
提出日時 | 2024-03-21 18:41:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 303 ms / 2,000 ms |
コード長 | 1,067 bytes |
コンパイル時間 | 237 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 82,824 KB |
最終ジャッジ日時 | 2024-03-21 18:41:11 |
合計ジャッジ時間 | 3,334 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
53,460 KB |
testcase_01 | AC | 36 ms
53,460 KB |
testcase_02 | AC | 35 ms
53,460 KB |
testcase_03 | AC | 35 ms
53,460 KB |
testcase_04 | AC | 36 ms
53,460 KB |
testcase_05 | AC | 35 ms
53,460 KB |
testcase_06 | AC | 41 ms
59,380 KB |
testcase_07 | AC | 68 ms
72,880 KB |
testcase_08 | AC | 303 ms
82,200 KB |
testcase_09 | AC | 282 ms
82,824 KB |
testcase_10 | AC | 255 ms
78,932 KB |
testcase_11 | AC | 257 ms
79,892 KB |
testcase_12 | AC | 221 ms
77,136 KB |
ソースコード
# 真ん中全探索か、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)