結果

問題 No.2718 Best Consonance
ユーザー flygonflygon
提出日時 2024-04-06 14:45:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,602 ms / 4,000 ms
コード長 1,785 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 82,604 KB
実行使用メモリ 117,364 KB
最終ジャッジ日時 2024-04-10 10:57:50
合計ジャッジ時間 29,407 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
67,908 KB
testcase_01 AC 58 ms
67,388 KB
testcase_02 AC 60 ms
67,264 KB
testcase_03 AC 67 ms
67,380 KB
testcase_04 AC 69 ms
68,304 KB
testcase_05 AC 68 ms
67,136 KB
testcase_06 AC 60 ms
67,872 KB
testcase_07 AC 63 ms
68,132 KB
testcase_08 AC 61 ms
66,756 KB
testcase_09 AC 117 ms
81,552 KB
testcase_10 AC 119 ms
81,136 KB
testcase_11 AC 119 ms
81,212 KB
testcase_12 AC 114 ms
80,416 KB
testcase_13 AC 116 ms
81,136 KB
testcase_14 AC 1,182 ms
115,284 KB
testcase_15 AC 960 ms
103,708 KB
testcase_16 AC 1,039 ms
107,480 KB
testcase_17 AC 804 ms
100,796 KB
testcase_18 AC 1,085 ms
109,216 KB
testcase_19 AC 868 ms
103,704 KB
testcase_20 AC 1,269 ms
115,276 KB
testcase_21 AC 1,205 ms
111,624 KB
testcase_22 AC 1,209 ms
112,116 KB
testcase_23 AC 689 ms
98,584 KB
testcase_24 AC 1,209 ms
116,888 KB
testcase_25 AC 1,281 ms
116,748 KB
testcase_26 AC 1,306 ms
117,364 KB
testcase_27 AC 1,313 ms
116,488 KB
testcase_28 AC 1,218 ms
117,076 KB
testcase_29 AC 1,296 ms
116,884 KB
testcase_30 AC 1,303 ms
116,440 KB
testcase_31 AC 1,304 ms
116,520 KB
testcase_32 AC 1,253 ms
116,340 KB
testcase_33 AC 1,300 ms
116,808 KB
testcase_34 AC 58 ms
68,100 KB
testcase_35 AC 59 ms
68,472 KB
testcase_36 AC 715 ms
114,956 KB
testcase_37 AC 59 ms
66,684 KB
testcase_38 AC 1,602 ms
115,196 KB
testcase_39 AC 59 ms
68,092 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 = [10**10]*(202020)
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