The Last Practice
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6819 Accepted Submission(s): 1375
Problem Description
Tomorrow is contest day, Are you all ready?
We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no chance to attend the Province-Final.
Now, your task is relaxing yourself and making the last practice. I guess that at least there are 2 problems which are easier than this problem.
what does this problem describe?
Give you a positive integer, please split it to some prime numbers, and you can got it through sample input and sample output.
We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no chance to attend the Province-Final.
Now, your task is relaxing yourself and making the last practice. I guess that at least there are 2 problems which are easier than this problem.
what does this problem describe?
Give you a positive integer, please split it to some prime numbers, and you can got it through sample input and sample output.
Input
Input file contains multiple test case, each case consists of a positive integer n(1<n<65536), one per line. a negative terminates the input, and it should not to be processed.
Output
For each test case you should output its factor as sample output (prime factor must come forth ascending ), there is a blank line between outputs.
Sample Input
60 12 -1
Sample Output
Case 1. 2 2 3 1 5 1 Case 2. 2 2 3 1Hint60=2^2*3^1*5^1
Author
lcy
Source
这个题目真的是很水,但是我真的过不了,主要是在于我的代码老是PE,该注意的问题全都注意了,唉,这真是太亏了啊!!!!
一分钟后:我发现最后一个的后面也有空格的,太坑了,没水平!!!!!!!
我的AC码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<ctime>
#include<algorithm>
using namespace std;
#define M 100000
bool visit[101000];
int prime[101000];
int num2[14000];
struct node
{
int num;
int a;
} unit[7000];
void table()
{
memset(visit,true,sizeof(visit));
int num = 0;
for (int i = 2; i <= M; ++i)
{
if (visit[i] == true)
{
num++;
prime[num] = i;
}
for (int j = 1; ((j <= num) && (i * prime[j] <= M)); ++j)
{
visit[i * prime[j]] = false;
if (i % prime[j] == 0) break; //µã¾¦Ö®±Ê
}
}
}
/*
4
Case 1.
2 2
23
Case 2.
23 1
-1
*/
/*
4
Case 1.
2 2
23
Case 2.
23 1
-1
*/
int main()
{
memset(prime, 0, sizeof(prime));
table();
int n;
int i,j,k;
int y=1;
//for(int i=1;i<7000;i++)
//printf("%d\n",prime[i]);
for(i=1; i<7000; i++)
{
unit[i].a=prime[i];
unit[i].num=0;
}
while(scanf("%d",&n),n>0)
{
if(y!=1)
printf("\n");
printf("Case %d.\n",y);
//for(i=1;i<7000;i++)
//printf("%d\n",unit[i].a);
for(i=1; i<7000; i++)
{
unit[i].num=0;
}
for(i=1; i<7000; i++)
{
if(n<0)
break;
while(n%unit[i].a==0)
{
unit[i].num++;
n=n/unit[i].a;
//printf("%d %d %d\n",unit[i].a,n,unit[i].num);
}
}
int t=0;
for(i=1; i<7000; i++)
{
if(unit[i].num)
{
num2[t]=unit[i].a;
num2[t+1]=unit[i].num;
t=t+2;
}
}
//printf("%d\n",t);
for(i=0; i<t-1; i++)
{
printf("%d ",num2[i]);
}
printf("%d \n",num2[t-1]);
//printf("\n");
y++;
}
return 0;
}