hdoj.1405 The Last Practice 20140825

来源:互联网 发布:天敏智能网络电视盒 编辑:程序博客网 时间:2024/06/05 07:02

The Last Practice

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


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
#include<stdio.h>#include<string.h>int p[66000];int s[7000];void f(){    int i,j;    memset(p,0,sizeof(p));    memset(s,1,sizeof(s));    for(i=2;i*i<65536;i++){        if(!p[i]){            for(j=i+i;j<65536;j+=i)                p[j]=1;        }    }    j=0;    for(i=2;i<65536;i++){        if(!p[i])                s[j++]=i;    }}int main(){    int n,i,j,x=1;    f();    while(scanf("%d",&n)!=EOF){        if(n<=0) break;        memset(p,0,sizeof(p));        if(x>1) printf("\n");        for(i=0;s[i]<=n;i++){            if(n==1) break;            while(n%s[i]==0){                p[i]++;                n/=s[i];            }        }        printf("Case %d.\n",x++);        ///int q=0;        for(j=0;j<=i;j++){            if(p[j]){                //if(q==0){                    ///printf("%d %d",s[j],p[j]);q++;                //}                //else                 printf("%d %d ",s[j],p[j]);            }        }        printf("\n");    }    return 0;}

0 0
原创粉丝点击