Identification Codes |
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB |
Total submit users: 6, Accepted users: 6 |
Problem 12892 : No special judgement |
Problem description |
MI6 uses a Spy Identification Code (SIC) to identify their spies. For example, J. B.2 has a SIC of 7. The SICs have been assigned to the spies in such a way that MI6 can easily refer to any group of spies by using a status code that is the product of all SICs of the spies in the group. |
Input |
On the first line one positive number: the number of test cases, at most 100. After that per test case: |
Output |
one line with a space-separated list of SICs for the status code, in increasing order. |
Sample Input |
5 7 12 64 72 1337 |
Sample Output |
7 3 4 4 16 2 4 9 7 191 |
唉。一个看样例猜题意的题目。题意我也不是怎么说得清楚。大致意思的是每个间谍都有自己的部门。啊,不说了。说说解法算了。看样例知道都是n这个数的因子。然后基本都是素数或者倍数。比如k的平方倍,为什么又没有k的立方倍呢?(详情请看样例3)2和4可以组成8也就是2的立方倍,显然,可以大胆的假设是平方倍的平方倍才可以。或者素数,这个当然大家都知道。于是代码就可以敲出来了。用素数筛选法把10e5前的素数晒出来,然后对n进行判断是否是因子,然后看是否有倍数的倍数存在。然后就额米有然后了。RE了一两次的原因还是再算倍数和倍数的时候h定义成了int类型太小了,导致了负数的产生。结果就悲剧了,改成__int64就可以Accept了。看到Accept还是有点小小的激动。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
using namespace std;
#define LL __int64
int t;
int a[100020],p[100000],b[100000];
void sf(long long n)
{
memset(a,0,sizeof(a));
memset(p,0,sizeof(p));
t=0;
for (int i=2;i<n;i++)
{
if (!a[i])
p[t++]=i;
for (int j=0;p[j] && (p[j]*i)<=n;j++)
{
a[p[j]*i]=1;
if (i % p[j]==0) break;
}
}
}
int main()
{
sf(100000);
int T,i;
LL n;
scanf("%d",&T);
while (T--)
{
scanf("%I64d",&n);
int k=0,ff=0;
for (i=0;i<t;i++)
{
if (n==1)
{
ff=1;
break;
}
if (n <= p[i])
{
ff=1;
b[k]=n;
k++;
break;
}
else
{
if (n % p[i]!=0) continue;
else
{
while (n % p[i]==0)
{
LL h=p[i];
while (n%h==0)
{
b[k]=h;
h*=h;
}
n/=sqrt(h);
k++;
}
}
}
}
if (ff==0) b[k++]=n;
sort(b,b+k);
for (i=0;i<k-1;i++)
printf("%d ",b[i]);
cout<<b[k-1]<<endl;
}
return 0;
}