湖大训练赛8 Identification Codes

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.
More precisely, the SICs are chosen in such a way that each status code 2 refers to a unique group of spies, and for each group of spies there is a unique status code referring to it. Write a program that, given a status code, returns the SICs of the spies that belong to the group corresponding to that status code.


Input

On the first line one positive number: the number of test cases, at most 100. After that per test case:
one line with an integer c (2<=c<=10^9): the status code.


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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值