HDU 1405 The Last Practice【注意输出格式】

来源:互联网 发布:php错误日志在哪 编辑:程序博客网 时间:2024/06/05 11:14

/*
中文题目 最后的练习
中文翻译-大意 举例说明60%2==0;60/2==30;30%2==0;30/2==15;15%2!=0;15%3==0;15/3==5;5%3!=0;5%5==0;根据例子可以看出60的质子含有2^2, 3^1, 5^1,按样例输出2【】2【】3【】1【】5【】1【】
解题思路:先打一个素数表,在直接求解就可以了
注意:除第一个数据外,其余输入后要空行;输出格式坑人啊。
关键点:输出格式
解题人:lingnichong
解题时间:2014-08-29 00:33:47
解题体会:没看清题意,凭着感觉写输出,结果oj好不客气的给我个PE
*/


The Last Practice

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7919    Accepted Submission(s): 1627


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.
 

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
6012-1
 

Sample Output
Case 1.2 2 3 1 5 1Case 2.2 2 3 1
Hint
60=2^2*3^1*5^1
 

Author
lcy
 

Source
杭电ACM集训队训练赛(IV)
 



/*本题注意格式为如下 60Case 1.2 2 3 1 5 112Case 2.2 2 3 112Case 3.2 2 3 1-1--------------------------------Process exited with return value 0Press any key to continue . . .*/#include<stdio.h>#include<string.h>#define MAXN 65536+10int a[MAXN],b[MAXN];int main(){int n,i,j,k=0,t=1;memset(a,0,sizeof(a));memset(b,0,sizeof(b));a[0]=a[1]=-1;for(i=2;i<MAXN/2;i++){for(j=2*i;j<MAXN;j+=i)if(a[j] != -1)a[j] = -1;}for(i=0;i<MAXN;i++){if(a[i]==0)b[k++] = i;}while(scanf("%d",&n),(n>=0)){if(t>1)printf("\n");printf("Case %d.\n",t++);for(i = 0; i <= n/2; i++){int count=0,flag=0;while(n%b[i]==0){count++;n /= b[i];flag=1;}if(flag==1)printf("%d %d ",b[i],count);}printf("\n");}return 0;} 




0 0
原创粉丝点击