先枚举$d=\gcd$,然后暴力枚举所有$d$的倍数,相当于求出若干个数中最大的互素对

假设选出的数依从大到小排序后为$a_{i}$,令$g_{i}=\min_{(a_{i},a_{j})=1}j$,则答案为$\max a_{i}\cdot a_{g_{i}}$

考虑一种比较奇怪的计算$g_{i}$的方式,先求出$tot=\sum_{j=1}^{n}[(a_{i},a_{j})=1]$,然后从$n$到1依次删除,直到删除的数中与$a_{i}$互素的数达到了$tot$个

关于$tot$的计算可以用莫比乌斯反演,即化简为$\sum_{d|a_{i}}\mu(d)\sum_{j=1}^{n}[d|a_{j}]$,记后面的式子为$f(d)$,可以在插入$a_{j}$时处理,那么就可以做到”均摊“单次插入/删除/询问$o(\ln n)$

之后考虑从$n$到1依次去删除,复杂度为$o(n-g_{i})$,但注意到若$g_{i}\ge g_{i-1}$那么没有意义,因此从$g_{i-1}$开始统计(即令$n=g_{i-1}$)就可以做到$o(n\ln^{2}n)$了(枚举$d$+计算$tot$的调和级数和gcd)

 1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 100005
4 vector<int>v,d[N];
5 int n,x,vis[N],mu[N],p[N],f[N];
6 long long ans;
7 int gcd(int x,int y){
8 if (!y)return x;
9 return gcd(y,x%y);
10 }
11 void update(int k,int p){
12 for(int i=0;i<d[k].size();i++)f[d[k][i]]+=p;
13 }
14 int query(int k){
15 int ans=0;
16 for(int i=0;i<d[k].size();i++)ans+=mu[d[k][i]]*f[d[k][i]];
17 return ans;
18 }
19 int main(){
20 mu[1]=1;
21 for(int i=2;i<N-4;i++){
22 if (!vis[i]){
23 p[++p[0]]=i;
24 mu[i]=-1;
25 }
26 for(int j=1;(j<=p[0])&&(i*p[j]<N-4);j++){
27 vis[i*p[j]]=1;
28 if (i%p[j])mu[i*p[j]]=-mu[i];
29 else{
30 mu[i*p[j]]=0;
31 break;
32 }
33 }
34 }
35 scanf("%d",&n);
36 memset(vis,0,sizeof(vis));
37 for(int i=1;i<=n;i++){
38 scanf("%d",&x);
39 vis[x]=1;
40 }
41 for(int i=1;i<N-4;i++)
42 for(int j=i;j<N-4;j+=i)d[j].push_back(i);
43 for(int i=1;i<N-4;i++){
44 v.clear();
45 for(int j=i;j<N-4;j+=i)
46 if (vis[j])v.push_back(j/i);
47 int m=v.size();
48 for(int j=0;j<m;j++)update(v[j],1);
49 for(int j=m-1,k=0;j>=0;j--){
50 int sum=query(v[j]);
51 while (sum){
52 if (gcd(v[j],v[k])==1){
53 sum--;
54 ans=max(ans,1LL*v[j]*v[k]*i);
55 }
56 update(v[k++],-1);
57 }
58 if (!j)
59 while (k<m)update(v[k++],-1);
60 }
61 }
62 printf("%lld",ans);
63 }

[cf1285F]Classical的更多相关文章

  1. JavaScript Patterns 6.2 Expected Outcome When Using Classical Inheritance

    // the parent constructor function Parent(name) { this.name = name || 'Adam'; } // adding functional ...

  2. What is classical music

    quanben's definition of classical music is a definition formed by the following aspects, 1. music wr ...

  3. Classical Inheritance in JavaScript

    JavaScript is a class-free, object-oriented language, and as such, it uses prototypal inheritance in ...

  4. ORACLE 11G R2 RAC classical install OGG12.1(LINUX) 经典抽取模式单项同步配置OGG12.1

    博文结构图如下: 一.环境描述以及注意事项 1.1 环境简介 IP 系统 Oracle版本 OGG版本 源端 172.16.10.16/36 RHEL6.5 oracle11204 12.1 目标端 ...

  5. How does Circus stack compare to a classical stack?

    Frequently Asked Questions - Circus 0.15.0 documentation https://circus.readthedocs.io/en/latest/faq ...

  6. JavaScript Patterns 6.1 Classical Versus Modern Inheritance Patterns

    In Java you could do something like: Person adam = new Person(); In JavaScript you would do: var ada ...

  7. The 50 Most Essential Pieces of Classical Music

    1. Die Zauberflöte ("The Magic Flute"), K. 620: Overture London Philharmonic Orchestra 7:2 ...

  8. Classical Binary Search

    Find any position of a target number in a sorted array. Return -1 if target does not exist. 与题目 Firs ...

  9. Classical method of machine learning

    PCA principal components analysis kmeans bayes spectral clustering svm EM hidden Markov models deep ...

随机推荐

  1. 题解 GT考试

    题目传送门 题目大意 给出\(n,m,k\),以及一个长度为\(m\)的数字串\(s_{1,2,...,m}\),求有多少个长度为\(n\)的数字串\(X\)满足\(s\)不出现在其中的个数模\(k\ ...

  2. NX Open 切削层加载

    UF_CUT_LEVELS_load Loads the current cut levels for the specified operation into the data structure ...

  3. Windows主机入侵排查

    检查系统信息.用户账号信息 系统信息 ● 查看系统版本以及补丁信息 systeminfo 用户账号信息 ● 基本使用 ○ 创建普通账号并加入administrarors 组 net user test ...

  4. 改善深层神经网络-week1编程题(GradientChecking)

    1. Gradient Checking 你被要求搭建一个Deep Learning model来检测欺诈,每当有人付款,你想知道是否该支付可能是欺诈,例如该用户的账户可能已经被黑客掉. 但是,反向传 ...

  5. Spring Cloud Alibaba整合Sentinel

    Spring Cloud Alibaba 整合 Sentinel 一.需求 二.实现步骤 1.下载 sentinel dashboard 2.服务提供者和消费者引入sentinel依赖 3.配置控制台 ...

  6. 函数指针和qsort函数

    1.函数指针的形式: 函数指针:int (*funcP) (int *a, int *b) 表示定义了一个funcP函数指针,指向了返回值为int类型,参数为int* 和int* 的函数 使用方式: ...

  7. C语言单片机项目实战超声波雷达测距

    本实验是基于MSP430利用HC-SR04超声波传感器进行测距,测距范围是3-65cm,讲得到的数据显示在LCD 1602液晶屏上. 模块工作原理如下 (1)采用 IO 触发测距,给至少 10us 的 ...

  8. 深入理解 Linux的进程,线程,PID,LWP,TID,TGID

    转载:https://www.linuxidc.com/Linux/2019-03/157819.htm 在Linux的top和ps命令中,默认看到最多的是pid (process ID),也许你也能 ...

  9. 全志Linux Tina编译demoOmxVdec错误

    测试裸流 Making install in demoOmxVdec make[6]: Entering directory '/home/liuxueneng/WorkCode/Homlet-Tin ...

  10. cf 12C Fruits(贪心【简单数学】)

    题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b ...