hdu_1405 The Last Practice
来源:互联网 发布:云数据库 免费 编辑:程序博客网 时间:2024/04/30 00:40
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1405
分析:先打印好素数表,然后让每个素数去除输入的n就好。
我的代码:
#include<stdio.h>#include<math.h>#define Max 65536struct Node{ int prime; int num;};Node p[Max];int If_P(int n){ int i; for(i=2;i<=sqrt(double(n));i++) { if(n%i==0) return 0; } return 1;}int main(){ // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int i; p[0].prime=2; int k=1; for(i=3;i<Max;i++) if(If_P(i)) //储存素数。 { p[k++].prime=i; } int tot=k; k=1; int n; while(~scanf("%d",&n)&&n>0) { if(k!=1) printf("\n"); printf("Case %d.\n",k++); for(i=0;i<tot;i++) p[i].num=0; //请空作为N的约数的素数个数/* 枚举每个素数。 for(i=0;i<tot;i++) { while(n%p[i].prime==0) { p[i].num++; n/=p[i].prime; if(n<=1) break; } if(n<=1) break; } */ int j=0; while(n>1) { while(n%p[j].prime==0&&n>1) //素数是N的约数 { n/=p[j].prime; p[j].num++; //素数的个数加一, } j++; } for(i=0;i<tot;i++) { // printf("i=%d \n",i); if(p[i].num) { printf("%d %d",p[i].prime,p[i].num); break; } } for(i+=1;i<=tot;i++) { if(p[i].num) printf(" %d %d",p[i].prime,p[i].num); } printf(" \n"); } return 0;}
总结:交了九次,前面一直WA,到了后面几次就是PE。。。o(>﹏<)o,WA是不仔细看题导致的,这题不是以-1结束,而是以非正数结束-_-!
PE是题目没说清吧,每个数后面带一个空格就好。
- hdu_1405 The Last Practice
- HDU1405:The Last Practice
- HDU1405 The Last Practice
- hdu1405 The Last Practice
- hdu1405 The Last Practice
- The Last Practice
- The Last Practice
- HDU The Last Practice
- hd1405 The Last Practice
- HDU1405 The Last Practice
- hdu 1405 The Last Practice
- The Last Practice hdu 1405
- HDU 1405 The Last Practice
- 【HDOJ】1405 -> The Last Practice
- HDU 1405The Last Practice
- 杭电-The Last Practice
- HDU 1405 The Last Practice
- The Last Practice(HDU1405)
- ADO 和ADO.NET数据访问功能的区别
- POJ3667Hotel(线段树)
- hdu 2955 Robberies
- Lab5 操作系统是如何工作的
- Linux多任务编程(六)---编写多进程程序及其代码
- hdu_1405 The Last Practice
- 迷宫问题 (上)栈 回溯法
- 普通成員函數的的重載形式
- Linux进程间通信(一)---进程间通信概述及其种类
- HDU1287 破译密码
- ok6410 u-boot-2012.04.01移植四增加MLC NAND支持
- 運算符的重載
- 转载:Socket 服务器端与客户端例子(异步模式)
- [黑马程序员]_简单的try catch用法和几个小例题