結果

問題 No.2718 Best Consonance
コンテスト
ユーザー detteiuu
提出日時 2026-07-19 20:34:37
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 1,819 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 226 ms
コンパイル使用メモリ 96,068 KB
実行使用メモリ 1,336,920 KB
最終ジャッジ日時 2026-07-19 20:35:30
合計ジャッジ時間 47,220 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33 MLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input = stdin.readline

class Eratosthenes:
    def __init__(self, n):
        self.isPrime = [True]*(n+1)
        self.minfactor = [-1]*(n+1)
        self.isPrime[0], self.isPrime[1] = False, False
        self.minfactor[1] = 1
        for i in range(2, n+1):
            if self.isPrime[i]:
                self.minfactor[i] = i
                for j in range(i*i, n+1, i):
                    self.isPrime[j] = False
                    if self.minfactor[j] == -1:
                        self.minfactor[j] = i
    
    def factorize(self, n):
        factor = []
        while n > 1:
            p = self.minfactor[n]
            cnt = 0
            while self.minfactor[n] == p:
                n //= p
                cnt += 1
            factor.append((p, cnt))
        return factor
    
    def divisor(self, n):
        ans = [1]
        pf = self.factorize(n)
        for p, c in pf:
            L = len(ans)
            for i in range(L):
                v = 1
                for _ in range(c):
                    v *= p
                    ans.append(ans[i]*v)
        return ans
    
E = Eratosthenes(10**5*2)

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

ans = 0
AB.sort()
NAB = []
for i in range(N):
    if i+1 < N:
        a, b = AB[i]
        c, d = AB[i+1]
        if a == c:
            ans = max(ans, b)
    if i+1 == N or AB[i][0] != AB[i+1][0]:
        NAB.append(AB[i][:])

C = [[] for _ in range(10**5*2+1)]
for A, B in AB:
    for d in E.divisor(A):
        C[d].append((A, B))
for i in range(10**5*2+1):
    C[i].sort(key=lambda x:x[0]*x[1], reverse=True)
    if 2 <= len(C[i]):
        MIN = C[i][0][0]
        for j in range(1, len(C[i])):
            ans = max(ans, C[i][j][1]*i//MIN)
            MIN = min(MIN, C[i][j][0])

print(ans)
0