HDU 1405The Last Practice
来源:互联网 发布:程序员 简历 编辑:程序博客网 时间:2024/05/17 01:28
The Last Practice
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7348 Accepted Submission(s): 1488
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
6012-1
Sample Output
Case 1.2 2 3 1 5 1Case 2.2 2 3 1Hint60=2^2*3^1*5^1
题目大意:把n质因数分解,举个简单例子,12的分解因数可以有以下几种:12=2x2x3=4x3=1x12=2x6,其中1,2,3,4,6,12都可以说是12的因数,即相乘的几个数等于一个自然数,那么这几个数就是这个自然数的因数。2,3,4中,2和3是质数,就是质因数,4不是质数。那么什么是质数呢?就是不能再拆分为除了1和它本身之外的因数的数,如2,3,5,7,11,13,17,19,23,29等等,质数没有什么特定的规律,不存在最大的质数。(转自百度百科)
代码:
#include<stdio.h>#include<memory.h>int a[10],p[10];//因为n不是太大,所以质数不是太多,初步算了一下大概2*3*5*11*13*17就超了n的最大范围。int main(){ int n,d=1,i,k; while((scanf("%d",&n)!=EOF)&&(n>0))//结束标志是负数,不要惯性认为以-1结束
{ if(d!=1) printf("\n");//控制输出数据之间的换行 k=0; memset(p,0,sizeof(p));/次数/清零 for(i=2;i<=n;i++) { if(n%i==0)//找出n的因子(因为是从2开始往上找的,所以这就是质数) { a[k]=i; while(n%i==0)//求质数的次方数 { n=n/i; p[k]++; } k++; } } printf("Case %d.\n",d); for(i=0;i<k;i++) { printf("%d %d ",a[i],p[i]);//输出,注意最后也有空格(这是在被坑了后从网上得知的) } printf("\n"); d++; }}
总结此题,不难,但问题很多,值得长记性。
0 0
- hdu 1405 The Last Practice
- The Last Practice hdu 1405
- HDU 1405 The Last Practice
- HDU 1405The Last Practice
- HDU 1405 The Last Practice
- 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 数论水题
- HDU 1405 The Last Practice 数学水题
- HDU 1405 The Last Practice【注意输出格式】
- HDU 1405 The Last Practice(数学题,变态的格式)
- HDU 1405 坑爹的The Last Practice
- 杭电 HDU ACM 1405 The Last Practice
- HDU——1405The Last Practice(试手map)
- IT书籍下载、编程语言书籍下载 拼吾爱
- 静态代码检查工具PC-Lint(一)
- ThinkPHP 自定义标签
- 基于GPU上的非结构化网格应用的性能分析和改进[1]
- freemodbus modbus TCP 学习笔记
- HDU 1405The Last Practice
- 如何卸载 SQL Server 2008实例
- Python标准库(非常经典的各种模块介绍)
- 静态代码检查工具PC-Lint(二)
- KODExplorer 简介
- 数据结构---堆及其相关函数
- C语言值传递问题
- https://oss.sonatype.org/content/groups/public/
- Android的消息循环机制 Looper Handler类分析