怎么办。。。RE了。。。。让我放一放好吗。。。。
题意:给你一个数,输出一种因子的组成,但是其中每个因子的组成是唯一的。若是没有能够唯一表达的因子组成的数,就是唯一表达的数。所以若是找到这么一组符合题意的因子,那么这个数就是不唯一表达的数。
可能表达不清楚。。。
思路大抵是。。。首先大张素数表,然后可以发现素数的平方,平方的平方等等都是唯一表达的数。
所以可以对输入的数分解质因数,然后记录每个质因数出现的个数,因为满足条件的次方是1,2,4,8,16....是一个等比数列,会发现当出现个数是2^n-1的时候就是满足条件的。可以以此进行筛选。
数组大小是乱开的。。。。
#include <stdio.h>
#include <iostream>
#include <algorithm>
#define maxn 100005
#define ll __int64
using namespace std;
int prime[maxn];
ll que[maxn];
void findprime()
{
ll i,j,k;
for(i=2;i<=10000;i++)
{
if(prime[i])
{
for(j=i*i;j<=100000;j+=i)
{
prime[j]=0;
}
}
}
}
void init()
{
for(int i=0;i<=1000;i++) prime[i]=1;
}
int main()
{
ll t;
scanf("%d",&t);
init();
findprime();
// if(prime[3]) printf("****3\n");
while(t--)
{
ll n;
ll top=0;
scanf("%I64d",&n);
ll i,j,k;
if(prime[n]) {printf("%I64d\n",n);continue;}
for(i=2;i<=n;i++)
{
if(prime[i]&&n%i==0)
{
int num=0;
j=n;
while(j%i==0)
{
num++;
j=j/i;
}
// printf("**num=%d\n",num);
if(num==1) {que[top++]=i;continue;}
ll tmp=i;
while(num)
{
if(num%2) {que[top++]=tmp;}// printf("num=%d\n",num);}
tmp*=tmp;
num/=2;
}
}
}
//que[top++]=n;
if(!top) printf("%I64d\n",n);
else {
sort(que,que+top);
for(i=0;i<top;i++) printf("%I64d ",que[i]);
printf("\n");}
}
return 0;
}