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

程序分析:由此题的标题就可以得知这个题目主要就是质因数分解,但是也一点要十分注意就是输出之间加一个空行,最后的那个数据不能加空行,还有,每组数据最后是有个空格的,不要忘记加上 不然你就会一直PE过不了的。

程序代码:

#include<stdio.h>
int prm[],a[]={};
int main()
{
int i,j,k,n,flag,num;
k=;
for(i=;i<=;i++)
if(!a[i]){
prm[k++]=i;
for(j=i+i;j<=;j+=i)
a[j]=;
}
flag=;
while()
{
scanf("%d",&n);
if(n<)break;
if(flag)
printf("\n");
flag++;
printf("Case %d.\n",flag);
for(i=;i<k&&prm[i]<=n;i++)
{
num=;
while(n%prm[i]==){
num++;
n=n/prm[i];
}
if(num!=){
if(n==)printf("%d %d \n",prm[i],num);
else printf("%d %d ",prm[i],num);
}
}
}
return ; }

HDU 1045(质因数分解)的更多相关文章

  1. [hdu 6069]素数筛+区间质因数分解

    给[L,R]区间的每一个数都质因数分解的复杂度可以达到(R-L)logR,真的涨姿势…… 另外,质因数分解有很重要的一点,就是只需要打sqrt(R)以内的素数表就够了……因为超过sqrt(R)的至多只 ...

  2. 求n!质因数分解之后素数a的个数

    n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...

  3. AC日记——质因数分解 1.5 43

    43:质因数分解 总时间限制:  1000ms 内存限制:  65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...

  4. 【BZOJ-4514】数字配对 最大费用最大流 + 质因数分解 + 二分图 + 贪心 + 线性筛

    4514: [Sdoi2016]数字配对 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 726  Solved: 309[Submit][Status ...

  5. 整数分解 && 质因数分解

    输入整数(0-30)分解成所有整数之和.每四行换行一次. 一种方法是通过深度优先枚举出解.通过递归的方式来实现. #include <stdio.h> #include <strin ...

  6. hdu 1045 Fire Net(最小覆盖点+构图(缩点))

    http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS     Memory Limit:32768KB   ...

  7. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  8. POJ1365 - Prime Land(质因数分解)

    题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...

  9. 数学概念——J - 数论,质因数分解

    J - 数论,质因数分解 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

随机推荐

  1. querySelector $() getElementBy区别

    参考 http://stackoverflow.com/questions/14377590/queryselector-and-queryselectorall-vs-getelementsbycl ...

  2. openstack中iptables的使用

    openstack中nova使用了iptables实现其网络相关功能,乍看openstack的iptables表比较复杂,整理了一下iptables的filter表和nat表的结构,以一个all in ...

  3. rsyslog 基本组成

    Facility 定义日志消息的来源,以方便对日志进行分类,facility 有以下几种: --kern 内核消息 --user 用户级消息 --mail 邮件系统消息 --daemon 系统服务消息 ...

  4. CSS 常用自定义样式

    目录: 1. 文本单行显示,并对超出部分截断以省略号代替: 2.列布局或栅格布局:比如:左侧固定宽度,右侧占满剩下的宽度: 章节: 1. 文本单行显示,并对超出部分截断以省略号代替:参见以下代码: d ...

  5. STC15?MSP430?ARM?DSP?

    自从大学毕业以来,发现属于自己的时间越来越少,每天忙于工作,导致在大学学到的东西都好生疏,特别是大一刚开始学的模电,单片机等,现在才慢慢的抓起来,然后在这个多核处理器流行的时代,单片机貌似快过时了,但 ...

  6. 九度OnlineJudge之1012:畅通工程

    题目描述: 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路 ...

  7. C#中窗体的一些简单运用(Sixteenth Day)

    从今天开始,我们进入到学window form的知识,今天简单的学习了一些控件和事件的运用.没有什么很全面的理论,所以今天就总结下所写的程序.一个简单的注册页面程序 注册页面程序 要求: 1:修改所有 ...

  8. iOS中的地图和定位

    文章摘自http://www.cnblogs.com/kenshincui/p/4125570.html#location  如有侵权,请联系删除. 概览 现在很多社交.电商.团购应用都引入了地图和定 ...

  9. C# Best Practices - Define Proper Classes

    Application Architecture Define the components appropriately for the application and create project ...

  10. Unity cg vertex and fragment shaders(二)

    着色器的一般结构: Shader "MyShader/MyShaderName" { Properties { // ... properties here ... } SubSh ...