hdu 1405 The Last Practice 数论水题
2013-11-17 17:17
260 查看
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.
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 1
Hint
60=2^2*3^1*5^1
Author
lcy
Source
杭电ACM集训队训练赛(IV)
这个题目真的是很水,但是我真的过不了,主要是在于我的代码老是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; }
相关文章推荐
- hdu 1405 The Last Practice(数论:欧拉函数的变形)
- HDU The Last Practice
- hdu 1405 The Last Practice (数学)
- hdu-oj 1405 The Last Practice
- HDU 1405 The Last Practice(求质因子及其个数 )
- hdu_1405 The Last Practice
- hdu 1405 The Last Practice (数学)
- YT02-简单数学课后题-1004 The Last Practice -(5.31日-烟台大学ACM预备队解题报告)
- HDOJ1405 The Last Practice(有坑)
- HDU1405:The Last Practice
- HDU 1405 The Last Practice
- 杭电-The Last Practice
- 一些项目——The Last Practice
- HDU1405:The Last Practice
- 关于杭电1405 The Last Practice 的问题
- The Last Practice hdu 1405
- 15HD_OJ——The Last Practice
- HDU 1405 坑爹的The Last Practice
- HDU 1405 The Last Practice
- HDU 1405 The Last Practice