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 

题意:如Hint所示.....,但是他的输出比较坑爹,开始一直不对然后没办法去百度了一下,大神说在输出结果最后还有空格,注意有空格!卧槽....  反正我是没有看出来

题解:就是求质因数,通过循环求质因数,如果n可以除尽i,进入while语句求i的次方,再用数组记录下来,最后在输出数组就好了...

代码如下:(详情见注释)
 #include <stdio.h>
int ans[];
int main()
{
int n,N=;
while(scanf("%d",&n)==&&n>=)
{
int j=;
if(N)
printf("\n"); //换行
N++;
for(int i=; i<=n; i++)
{
if(n%i==) //如果可以除尽
{
int m=; //注意清零
while(n%i==) //循环求 次数
{
m++;
n=n/i;
}
ans[j++]=i; //依次储存下来
ans[j++]=m;
}
}
printf("Case %d.\n",N); for(int k=; k<j; k++)
printf("%d ",ans[k]);  //输出
printf("\n");
}
}


HDU 1405 第六周 J题的更多相关文章

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

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

  2. HDU 1465 第六周L题

    Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!  做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样.  ...

  3. HDU 2669 第六周 I题

    Description The Sky is Sprite.  The Birds is Fly in the Sky.  The Wind is Wonderful.  Blew Throw the ...

  4. hdu1405 第六周J题(质因数分解)

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

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

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

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

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

  7. Codeforces 559A 第六周 O题

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

  8. 第六周 N题

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

  9. HDU1465 第六周L题(错排组合数)

    L - 计数,排列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descrip ...

随机推荐

  1. iOS数据持久化存储:归档

    在平时的iOS开发中,我们经常用到的数据持久化存储方式大概主要有:NSUserDefaults(plist),文件,数据库,归档..前三种比较经常用到,第四种归档我个人感觉用的还是比较少的,恰恰因为用 ...

  2. 重构25-Introduce Design By Contract checks(契约式设计)

    契约式设计(DBC,Design By Contract)定义了方法应该包含输入和输出验证.因此,可以确保所有的工作都是基于可用的数据,并且所有的行为都是可预料的.否则,将返回异常或错误并在方法中进行 ...

  3. SQL Server之内连接 左连接 右连接 全连接 交叉连接

    SELECT * FROM Table_A GO SELECT * FROM Table_B GO --内连接 SELECT a.*, b.* FROM Table_A a JOIN Table_B ...

  4. JAVA数字证书制作生成

    1.加密算法 为了网络通讯中的报文安全,一般需要对报文进行加密,目前常用的加密算法有: 非对称加密算法:又称公钥加密算法,如RSA.DSA/DSS,最常用的就是RSA算法(算法公开,可自行百度了解算法 ...

  5. POJ 1308 Is It A Tree? (并查集)

    Is It A Tree? Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24237   Accepted: 8311 De ...

  6. jQuery中的渐变动画效果

    jQuery中的渐变动画效果jQuery中的渐变动画效果

  7. sgu 185 最短路建网络流

    题目:给出一个图,从图中找出两条最短路,使得边不重复. 分析:既然是最短路,那么,两条路径上的所有节点的入边(s,x).出边(x,e)必定是最优的,即 dis[x] = dis[s]+edge_dis ...

  8. SqlServer知识总结

    SqlServer查询表的列数 select count(*) from sysobjects a join syscolumns b on a.id=b.id where a.name='表名' 在 ...

  9. What Makes a Good Programmer Good?

    I’ve worked with a lot of programmers over the years — some of them super amazing, and some distinct ...

  10. Hibernate总结--MyEclipse的小bug

    今天笔者在写一个用S2SH的程序的时候,出现了下面的错误: org.springframework.beans.factory.BeanCreationException: Error creatin ...