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. 《ACM国际大学生程序设计竞赛题解I》——6.11

    pku 1107: Description Weird Wally's Wireless Widgets, Inc. manufactures an eclectic assortment of sm ...

  2. H - Pots

    题目大意: 有一个瓶子A和一个瓶子B,可以有三种操作倒满,倒空,或者把瓶子A倒向瓶子B(或者把瓶子B倒向瓶子A),可以扩展出6种操作,没什么简单的写法,只能一种一种的写..... 当然是使用广搜... ...

  3. 【索引】Volume 0. Getting Started

    AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 0. Getting Started 10055 - Hashmat the Brav ...

  4. 优化exp/imp导入导出速度大全

    .exp  个相关的参数:DIRECT和RECORDLENGTH参数. DIRECT参数定义了导出是使用直接路径方式(DIRECT=Y),还是常规路径方式(DIRECT=N).常规路径导出使用SQL ...

  5. git如何clone所有的远程分支

    问题: 文/赖忠标 周末在家里改了下代码,新建了个angular版本的分支,然后push到coding.net上面了. 今天,到公司却不知道怎么拉取这个angular分支到公司的电脑上面.如下图(1) ...

  6. Java 二分查找

    public int binarySearch(int[] nums, int target) { int low = 0; int high = nums.length; while (low &l ...

  7. Linux Epoll介绍和程序实例

    Linux Epoll介绍和程序实例 1. Epoll是何方神圣? Epoll但是当前在Linux下开发大规模并发网络程序的热门人选,Epoll 在Linux2.6内核中正式引入,和select类似, ...

  8. html contenteditable

    contenteditable 是html中的一個屬性,在HTML中,某些元素設置 contenteditable='true'  屬性時可以開啟該元素的編輯模式,contenteditable 可以 ...

  9. DTD简单使用

    DTD:Document Type Definition DTD是一种简单的XML约束模式语言 DTD文档必须以utf-8或unicode编码 注释方式与HTML.XML文档相同 DTD文档的引用:紧 ...

  10. codevs 1689 搭建高塔

    /*机智sort二维转一维*/ #include<iostream> #include<cstdio> #include<cstring> #include< ...