結果

問題 No.2519 Coins in Array
ユーザー MasKoaTS
提出日時 2023-10-17 23:05:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 81,904 KB
実行使用メモリ 108,960 KB
最終ジャッジ日時 2024-09-17 20:14:28
合計ジャッジ時間 7,404 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import gcd
input = sys.stdin.readline

def f(x, y):
    if(gcd(x, y) == 1):
        return (x - 1) * (y - 1)
    return 0


n = int(input())
a = list(map(int, input().split()))

ans = f(a[0], a[1])
ops = [(1, 2)]
if(n == 2):
    pass
elif(n == 3):
    ans_lis = [f(f(a[0], a[1]), a[2]), f(f(a[0], a[2]), a[1]), f(f(a[1], a[2]), a[0])]
    op_lis = [[(1, 2), (1, 2)], [(1, 3), (1, 2)], [(2, 3), (1, 2)]]
    ans = 10 ** 18
    for x, y in zip(ans_lis, op_lis):
        if(x >= ans):
            continue
        ans = x
        ops = y
else:
    ans = 0
    ops = [(1, 2) for _ in [0] * (n - 1)]

print(ans)
for x, y in ops:
    print(x, y)
0