結果

問題 No.2519 Coins in Array
ユーザー aaaaaaaaaa2230
提出日時 2023-10-28 09:45:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 823 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 106,880 KB
最終ジャッジ日時 2024-09-25 16:14:20
合計ジャッジ時間 6,076 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

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


def f(A,inds):
    ans = [[inds[-1],inds[-2]]]
    
    a1,a2 = A[-1],A[-2]
    num = 10**18
    if math.gcd(a1,a2) != 1:
        num = 0
    else:
        num = (a1-1)*(a2-1)

    for i in range(len(A)-2):
        if math.gcd(num,A[0]) != 1:
            num = 0
        if num:
            num = (num-1) * (A[0]-1)
        ans.append([1,2])
    
    return num,ans

if n >= 4:
    print(0)
    for i in range(n-1):
        print(1,2)

else:

    inds = [i+1 for i in range(n)]

    res = 10**18
    ans = []
    for i in range(n):
        num,ans2 = f(A,inds)
        if num < res:
            res = num
            ans = ans2
        
        inds = inds[1:] + [inds[0]]
        A = A[1:] + [A[0]]
    
    print(res)
    for a in ans:
        print(*a)
0