結果
問題 | No.816 Beautiful tuples |
ユーザー | roaris |
提出日時 | 2019-07-25 20:27:50 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 17 ms / 1,500 ms |
コード長 | 800 bytes |
コンパイル時間 | 126 ms |
コンパイル使用メモリ | 10,760 KB |
実行使用メモリ | 7,944 KB |
最終ジャッジ日時 | 2023-09-15 00:05:09 |
合計ジャッジ時間 | 1,165 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
7,816 KB |
testcase_01 | AC | 16 ms
7,820 KB |
testcase_02 | AC | 17 ms
7,904 KB |
testcase_03 | AC | 15 ms
7,788 KB |
testcase_04 | AC | 16 ms
7,880 KB |
testcase_05 | AC | 15 ms
7,880 KB |
testcase_06 | AC | 14 ms
7,944 KB |
testcase_07 | AC | 14 ms
7,900 KB |
testcase_08 | AC | 15 ms
7,780 KB |
testcase_09 | AC | 15 ms
7,820 KB |
testcase_10 | AC | 14 ms
7,788 KB |
testcase_11 | AC | 14 ms
7,836 KB |
testcase_12 | AC | 14 ms
7,912 KB |
testcase_13 | AC | 15 ms
7,788 KB |
testcase_14 | AC | 13 ms
7,844 KB |
ソースコード
def factorize(n): fct = [] div = 2 while div ** 2 <= n: cnt = 0 while n % div == 0: n //= div cnt += 1 if cnt > 0: fct.append((div, cnt)) div += 1 if n > 1: fct.append((n, 1)) return fct def dfs(fct, depth, cur): div, cnt = fct[depth] if depth == len(fct) - 1: return [cur*div**i for i in range(cnt+1)] rseq = [] for i in range(cnt+1): rseq += dfs(fct, depth+1, cur*div**i) return rseq A, B = map(int, input().split()) fct = factorize(A+B) C_cand = list(sorted(dfs(fct, 0, 1))) for C in C_cand: if A != C and B != C and (B + C) % A == 0 and (C + A) % B == 0: print(C) break else: print(-1)