Topic
directly enumerate gcd gcdg c d is fine.
This kind of question is like this. Enumerategcd gcdg c d
want to see more enumerationgcd gcdFor g c d questions and more number
theoryquestions, please see the following ↓Introduction to
Number Theory Number Theory 1 Euler Function Euler Theorem Number Theory Block
Number Theory 2 Combination Number, Extended Euclid, Inverse Element
#include<cstdio>
#define N int(1e6+1)
#define reg register
inline void read(int &x){
int s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){
s=(s<<3)+(s<<1)+(ch&15);ch=getchar();}
x=s*w;
}
inline int maxx(int a, int b){
return a>b?a:b;}
int n,maxnum,a[N],fac[N],ans[N];
int main(){
read(n);
for(reg int i=1;i<=n;i++){
read(a[i]);maxnum=maxx(maxnum,a[i]);
for(reg int j=1;j*j<=a[i];j++)
if(a[i]%j==0){
fac[j]++;
if(j*j!=a[i])fac[a[i]/j]++;
}
}
for(reg int i=maxnum;i>1;i--){
for(reg int j=1;j<=fac[i];j++)if(!ans[j])ans[j]=i;
}
for(reg int i=1;i<=n;i++){
if(!ans[i])ans[i]=1;
printf("%d\n",ans[i]);
}
}