結果
| 問題 | 
                            No.2519 Coins in Array
                             | 
                    
| コンテスト | |
| ユーザー | 
                             MasKoaTS
                         | 
                    
| 提出日時 | 2023-10-27 12:43:21 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 243 ms / 2,000 ms | 
| コード長 | 1,369 bytes | 
| コンパイル時間 | 225 ms | 
| コンパイル使用メモリ | 82,764 KB | 
| 実行使用メモリ | 125,768 KB | 
| 最終ジャッジ日時 | 2024-09-25 12:59:51 | 
| 合計ジャッジ時間 | 11,185 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 37 | 
ソースコード
import itertools as iter
import collections as coll
import heapq as hq
import bisect as bis
from decimal import Decimal as dec
from functools import cmp_to_key
import math
import sys
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
sys.setrecursionlimit(10 ** 6)
inp = sys.stdin.readline
input = lambda : inp()[:-1]
getN = lambda : int(inp())
getNs = lambda : map(int, inp().split())
getList = lambda :list(map(int, inp().split()))
getStrs = lambda n : [input() for _ in [0] * n]
getEdges = lambda n : [[x - 1 for x in getNs()] for _ in [0] * n]
def yexit(): print("Yes"); exit(0)
def nexit(): print("No"); exit(0)
pi = 3.141592653589793
mod = 1000000007
MOD = 998244353
INF = 4611686018427387903
dx = [1, 0, -1, 0];  dy = [0, 1, 0, -1]
#di = coll.defaultdict(int)
def f(x, y):
    if(math.gcd(x, y) != 1):
        return 0
    return (x - 1) * (y - 1)
 
"""
Main Code
"""
n = getN()
a = getList()
ans = INF
ops = []
if(n == 2):
    ans = f(a[0], a[1])
    ops = [(1, 2)]
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])]
    ops_lis = [[(1, 2), (1, 2)], [(1, 3), (1, 2)], [(2, 3), (1, 2)]]
    for x, y in zip(ans_lis, ops_lis):
        if(ans <= x):
            continue
        ans, ops = x, y
else:
    ans = 0
    ops = [(1, 2) for _ in [0] * (n - 1)]
print(ans)
for x, y in ops:
    print(x, y)
            
            
            
        
            
MasKoaTS