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. ActionScript接收socket服务器发送来的数据

    原文地址:http://www.asp119.com/news/2009522181815_1.htm 从socket中接收数据的方法取决于你使用socket类型,Socket和XMLSocket都可 ...

  2. SRM 390(1-250pt)

    DIV1 250pt 题意:给定整数n和k,问最少需要多少个n连接在一起形成的新整数t,使得t是k的倍数.如果不能形成倍数,输出-1.k <= 10^5,n <= 10^9. 解法:不断增 ...

  3. winscp自动执行脚本

    我们经常使用WinSCP工具通过sftp协议上传获取文件,本文描述通过bat批量处理文件. 首先,我们打开dos命令窗口使用 cd \d :D\WinSCP 打开WinSCP安装目录 上传文件: wi ...

  4. Http报文 状态码

    一.HTTP报文 1.HTTP报文介绍 HTTP报文:用于HTTP协议交互的信息. HTTP报文由报文头部和报文主体(非必须)构成,中间由空行来分隔. 1.1 请求报文:客户端发起的报文. 1).报文 ...

  5. .Net动态加载插件-反射

    /// <summary> /// 动态加载插件 /// </summary> void LoadPlugin() { string[] ps = Directory.GetF ...

  6. [Angular 2] Exposing component properties to the template

    Showing you how you can expose properties on your Controller to access them using #refs inside of yo ...

  7. 獲取 Textarea 的光標位置(摘自網絡)

    在任何编辑器中,获取光标位置都是非常重要的,很多人可能认为较难,其实只要处理好浏览器的兼容,还是比较容易实现的.下面我们一起来看看如何获取到 Textarea 元素中的光标位置.首先,我们用 rang ...

  8. Unicode 与多字节编码

    int _tmain(int argc, _TCHAR* argv[]) { //定义LPWSTR 类型的宽字符串 LPWSTR szUnicode = L"This is a Unicod ...

  9. C#_事件委托

    CarDealer类 事件发布程序 using System; using System.Collections.Generic; using System.Linq; using System.Te ...

  10. 地址栏访问Action,后来方法执行两次

    SSH框架,在地址栏输入URL访问Action,后台访问会访问两次.很奇怪. 经排查,最终问题在于方法名称写错了.将getOpinionByPN()修改成queryOpinionByPN(),没有问题 ...