結果

問題 No.2718 Best Consonance
ユーザー flygonflygon
提出日時 2024-04-06 14:41:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,069 ms / 4,000 ms
コード長 1,795 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 150,552 KB
最終ジャッジ日時 2024-04-10 10:57:21
合計ジャッジ時間 30,715 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
66,224 KB
testcase_01 AC 52 ms
67,612 KB
testcase_02 AC 54 ms
65,620 KB
testcase_03 AC 53 ms
66,172 KB
testcase_04 AC 54 ms
65,696 KB
testcase_05 AC 53 ms
66,684 KB
testcase_06 AC 53 ms
65,352 KB
testcase_07 AC 53 ms
66,996 KB
testcase_08 AC 51 ms
65,784 KB
testcase_09 AC 106 ms
79,564 KB
testcase_10 AC 107 ms
80,032 KB
testcase_11 AC 110 ms
79,640 KB
testcase_12 AC 103 ms
79,208 KB
testcase_13 AC 105 ms
80,288 KB
testcase_14 AC 1,230 ms
139,456 KB
testcase_15 AC 988 ms
124,172 KB
testcase_16 AC 1,006 ms
127,888 KB
testcase_17 AC 845 ms
120,648 KB
testcase_18 AC 1,155 ms
133,128 KB
testcase_19 AC 965 ms
124,136 KB
testcase_20 AC 1,330 ms
139,620 KB
testcase_21 AC 1,212 ms
134,560 KB
testcase_22 AC 1,261 ms
135,800 KB
testcase_23 AC 750 ms
115,808 KB
testcase_24 AC 1,363 ms
149,780 KB
testcase_25 AC 1,411 ms
150,020 KB
testcase_26 AC 1,362 ms
150,500 KB
testcase_27 AC 1,354 ms
149,564 KB
testcase_28 AC 1,384 ms
149,972 KB
testcase_29 AC 1,402 ms
149,960 KB
testcase_30 AC 1,340 ms
149,904 KB
testcase_31 AC 1,411 ms
149,136 KB
testcase_32 AC 1,359 ms
149,968 KB
testcase_33 AC 1,417 ms
150,552 KB
testcase_34 AC 56 ms
66,688 KB
testcase_35 AC 56 ms
66,440 KB
testcase_36 AC 839 ms
113,420 KB
testcase_37 AC 56 ms
65,728 KB
testcase_38 AC 2,069 ms
114,004 KB
testcase_39 AC 55 ms
65,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd
class Era:
    def __init__(self, n):
        self.N = n
        self.l = [i for i in range(n+1)]
        for i in range(2,min(n,n//2+10)):
            if self.l[i] == i:
                for p in range(i+i,n+1,i):
                    if self.l[p] == p:
                        self.l[p] = i
    # 素数判定
    def isprime(self,n):
        return self.l[n] == n

    # 素因数分解
    def primes(self,n):
        ans = []
        now = n
        while now != 1:
            if not ans:
                ans.append([self.l[now], 1])
            else:
                if ans[-1][0] == self.l[now]:
                    ans[-1][1] += 1
                else:
                    ans.append([self.l[now], 1])
            now //= self.l[now]
        return ans
    
    # 約数列挙
    def facts(self,n):
        pf = self.primes(n)
        ans = [1]
        for pn, cnt in pf:
            tmp = [pow(pn, i) for i in range(1, cnt+1)]
            m = len(ans)
            for num in tmp:
                for i in range(m):
                    ans.append(ans[i]*num)
        return ans

era = Era(202020)
n = int(input())
ab = []
cs = []
for i in range(n):
    a,b= map(int,input().split())
    c = a*b
    cs.append((c,i))
    ab.append([a,b])

cs.sort()
cs = cs[::-1]
d = defaultdict(lambda :10**10)
ans = 0
for ci, i in cs:
    ai,bi = ab[i]
    fs = era.facts(ai)
    tmp = 0
    for num in fs:
        if d[num] == 10**10: continue
        tmp = max(tmp, bi*num//d[num])
    
    for num in fs:
        d[num] = min(d[num], ai)
    ans = max(tmp, ans)
    
print(ans)
0