J - 数论,质因数分解

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

 

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 
 题解;

唯一分解定理,可以百度一下,这道题就是求一个数有哪些质数组成,其中相同的要用次方表示,比如60=2^2*3^1*5^1。负数时,结束程序。

这道题听别人说有坑,就是格式的问题。知道了就少走了很多弯路

1,每个输出数字后面都有空格(每组输出最后有一个空格)
2,两测试数据间有空行(最后一组数据后面没有空行)
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
int a[],p[];
int main()
{
int n,i,k=;
while(cin>>n&&(n>))
{
if(k>) cout<<endl; //从第二个案例开始要有空行
memset(p,,sizeof(p));
for(i=; i<=n; i++) //不断地计算质因子
{
while(n%i==)
{
n=n/i;
p[i]++;
}
}
printf("Case %d.\n",k++);
for(i=; i<; i++) //在规定范围内的n含有的质因子不会超过10000,算是投机取巧了
{
if(p[i]>)
printf("%d %d ",i,p[i]); //空格。。有一个空格看到没
}
cout<<endl;
}
}

hdu1405 第六周J题(质因数分解)的更多相关文章

  1. HDU 1405 第六周 J题

    Description Tomorrow is contest day, Are you all ready?  We have been training for 45 days, and all ...

  2. hdu 4548 第六周H题(美素数)

    第六周H题 - 数论,晒素数 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   De ...

  3. 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)

    第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...

  4. 洛谷 - P1072 Hankson - 的趣味题 - 质因数分解

    https://www.luogu.org/problemnew/show/P1072 一开始看了一看居然还想放弃了的. 把 \(x,a_0,a_1,b_0,b_1\) 质因数分解. 例如 \(x=p ...

  5. Codeforces 559A 第六周 O题

    Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...

  6. 2014 HDU多校弟六场J题 【模拟斗地主】

    这是一道5Y的题目 有坑的地方我已在代码中注释好了 QAQ Ps:模拟题还是练的太少了,速度不够快诶 //#pragma comment(linker, "/STACK:16777216&q ...

  7. NOIP2012-普及组复赛-第一题-质因数分解

    题目描述 Description 已知正整数n是两个不同的质数的乘积,试求出两者中较大的那个质数.  输入输出格式 Input/output 输入格式:输入只有一行,包含一个正整数n.输出格式:输出只 ...

  8. 第六周 N题

    Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (h ...

  9. 洛谷 P1072 Hankson 的趣味题 —— 质因数分解

    题目:https://www.luogu.org/problemnew/show/P1072 满足条件的数 x 一定是 a1 的倍数,b1 的因数,a0/a1 与 x/a1 互质,b1/b0 与 b1 ...

随机推荐

  1. [Locked] Palindrome Permutation I & II

    Palindrome Permutation I Given a string, determine if a permutation of the string could form a palin ...

  2. Git git rebase 使用

      原文:http://gitbook.liuhui998.com/4_2.html 一.基本 git rebase用于把一个分支的修改合并到当前分支. 假设你现在基于远程分支"origin ...

  3. Linux一键安装PHP/JAVA环境OneinStack

    OneinStack 是一款PHP/JAVA环境一键配置工具.                         OneinStack包含以下组合   lnmp(Linux + Nginx+ MySQL ...

  4. 互联网TCP/IP五层模型(一)

    转载自:阮一峰 我们每天使用互联网.你是否想过,它是怎样实现的? 全世界几十亿台电脑,连接在一起,两两通信. 上海的某一块网卡送出信号,洛杉矶的还有一块网卡竟然就收到了.两者实际上根本不知道对方的物理 ...

  5. [Rails Level 2] Ground up

    1. Rails commends line: Example: rails new blog --skip-test-unit --database=postgresql

  6. Linux 监控CPU 温度

      安装测试系统: 硬件:普通PC机, 软件:redhat linux as 4  2.6 .9 , 安装系统自带的lm_sensors-2.8.7-2.i386 你也可以从[url]http://w ...

  7. HDU 5033 Building(单调栈维护凸包)

    盗张图:来自http://blog.csdn.net/xuechelingxiao/article/details/39494433 题目大意:有一排建筑物坐落在一条直线上,每个建筑物都有一定的高度, ...

  8. 请输出in.txt文件中的2 4 6 8 9 10 12行

    in.txt文件: 学号 姓名 性别 年龄 1001 张三 男 18 1002 赵四 男 19 1003 李丽 女 18 1004 刘芳 女 32 1005 王五 男 54 1006 小明 男 32 ...

  9. 移动Web开发技巧

    META相关 1. 添加到主屏后的标题(IOS) <meta name="apple-mobile-web-app-title" content="标题" ...

  10. PHP 关于文件操作的简单介绍

    文件操作一直是Web程序员头疼的地方,而文件操作在CMS这样的系统中又是必须的.如今,PHP文件操作的函数内容已经非常强大,文件这部分也是学习PHP非常重要的一部分,希望大家不要忽略.这篇文章会简单介 ...