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. 写了个小爬虫,为何用上代理ip总是出现错误。

    import urllib.request import re import os import random import threading def url_open(url): #在第8到第12 ...

  2. IIS7内建账号,应用程序池

    在IIS7以前的IIS版本中有一个本地帐号,是在安装时创建的,叫做 IUSR_MachineName.一旦启用匿名身份认证,这个IUSR_MachineName帐号就是IIS默认使用的身份(ident ...

  3. css 样式

    <!doctype html> <html lang="en"> <head> <meta name="Generator&qu ...

  4. kafka集群搭建与apiclient创建

    曾经的消息队列(activeMQ)对于大数据吞吐率不行,但kafka非常好的攻克了此类问题.而且以集群的方式进行扩展.可谓相当强大: 集群搭建方式很轻量级.仅仅需将tar包复制到server,解压,改 ...

  5. Android应用开发基础篇(4)-----TabHost(选项卡)

    一.概述 TabHost是一种用来显示标签的组件,不清楚?看一下来电通这个应用就知道了.这个组件用起来与其他组件不太一样,它需要继承TabActivity这个类,还有它的布局文件与我们平时用的也有些不 ...

  6. linux多线程示例

    #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h& ...

  7. webservice跨域上传图片

    1.上传文件,在一般处理程序中处理 //1.接收post过来的文件 HttpPostedFile file = context.Request.Files[]; || file.ContentLeng ...

  8. DropDownList为啥总是获取第一项的值???

    小菜: DropDownList控件绑定的数据,在获取数据时总是获取到第一项,很是郁闷,怎么回事,于是就各种想,都没有找到问题的原因. 请看下面的代码 前台代码: <asp:DropDownLi ...

  9. 如何最简单的优化MySql

    1.创建索引,一定要根据实际情况来创建,如果是连接表查询,如一个主帐号连接多个子帐号,可以考虑两个或三个以上的多索引: 2.合理利用时间排序,由于大多数表格用时间来排序,数据量相当大的时候,在时间列上 ...

  10. [Jobdu] 题目1367:二叉搜索树的后序遍历序列

    题目描述: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. 输入: 每个测试案例包括2行: 第一行为1个整数 ...