【数学】CF1419E - Decryption
作者:互联网
我认为可以这么写,先看看对不对……
const int MAXN = 100000 + 5;
int n;
int p[100005];
int ptop;
int d[100005];
int dtop;
int a[100005];
int atop;
void getp(int n) {
ptop = 0;
for(int i = 2; i * i <= n; ++i) {
if(n % i == 0) {
p[++ptop] = i;
while(n % i == 0)
n /= i;
}
}
if(n != 1)
p[++ptop] = n;
//reverse(p + 1, p + 1 + ptop);
}
void getd(int n) {
dtop = 0;
for(int i = 1; i * i <= n; ++i) {
if(n % i == 0) {
d[++dtop] = i;
if(i * i != n)
d[++dtop] = n / i;
}
}
sort(d + 1, d + 1 + dtop);
}
void geta(int n) {
atop = 0;
int cn = n;
for(int i = 1; i <= ptop; ++i) {
int ccn = cn / p[i];
int batop = atop + 1;
for(int j = 1; j * j <= ccn; ++j) {
if(ccn % j == 0) {
if( j * p[i] != p[i]*p[i + 1] && j * p[i] != n)
a[++atop] = j * p[i];
if(j * j != ccn && ccn / j != p[i + 1] && ccn / j * p[i] != n)
a[++atop] = ccn / j * p[i];
}
}
int eatop = atop + 1;
sort(a + batop, a + eatop);
if(i + 1 <= ptop) {
a[++atop] = p[i] * p[i + 1];
while(cn % p[i] == 0)
cn /= p[i];
} else
a[++atop] = n;
}
}
void solve() {
n = readInt();
getp(n);
if(ptop == 1) {
getd(n);
for(int i = 2; i <= dtop; ++i)
printf("%d%c", d[i], " \n"[i == dtop]);
puts("0");
return;
}
if(ptop == 2) {
if(p[1]*p[2] == n) {
printf("%d %d %d\n", p[1], p[2], n);
puts("1");
return;
}
}
geta(n);
for(int i = 1; i <= atop; ++i)
printf("%d%c", a[i], " \n"[i == atop]);
puts("0");
return;
}
标签:Decryption,const,dtop,int,100005,数学,CF1419E,ptop 来源: https://www.cnblogs.com/purinliang/p/13698404.html