1059. Prime Factors (25)
Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1* p2^k2 *…*pm^km.
Input Specification:
Each input file contains one test case which gives a positive integer N in the range of long int.
Output Specification:
Factor N in the format N = p1^k1 * p2^k2 *…*pm^km, where pi's are prime factors of N in increasing order, and the exponent ki is the number of pi -- hence when there is only one pi, ki is 1 and must NOT be printed out.
Sample Input:
- 97532468
Sample Output:
- 97532468=2^2*11*17*101*1291
- #include<stdio.h>
- #include<math.h>
- #include<vector>
- using namespace std;
- int main()
- {
- int n,i,j;
- vector<int> vv;
- for(i= ;i<=;i++)
- {
- bool is = true;
- for(j=;j<=sqrt(i*1.0);j++)
- {
- if(i % j == )
- {
- is = false;
- break;
- }
- }
- if(is) vv.push_back(i);
- }
- while(scanf("%d",&n)!=EOF)
- {
- printf("%d=",n);
- bool fir = true;
- if(n == ) printf("");
- else
- {
- i = ;
- while(n != )
- {
- if(n % vv[i] == )
- {
- int tem = ;
- while(n % vv[i] == )
- {
- ++tem;
- n = n / vv[i];
- }
- if(fir)
- {
- printf("%d",vv[i]);
- fir = false;
- }
- else
- {
- printf("*%d",vv[i]);
- }
- if(tem > )
- {
- printf("^%d",tem);
- }
- }
- ++i;
- }
- }
- printf("\n");
- }
- return ;
- }
1059. Prime Factors (25)的更多相关文章
- PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime ...
- 1059 Prime Factors (25分)
1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ...
- PAT 1059. Prime Factors (25) 质因子分解
题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...
- PAT Advanced 1059 Prime Factors (25) [素数表的建⽴]
题目 Given any positive integer N, you are supposed to find all of its prime factors, and write them i ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
- PAT (Advanced Level) 1059. Prime Factors (25)
素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...
- 【PAT甲级】1059 Prime Factors (25 分)
题意: 输入一个正整数N(范围为long int),输出它等于哪些质数的乘积. trick: 如果N为1,直接输出1即可,数据点3存在这样的数据. 如果N本身是一个质数,直接输出它等于自己即可,数据点 ...
- pat1059. Prime Factors (25)
1059. Prime Factors (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...
- PAT 1059 Prime Factors[难]
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ...
随机推荐
- C语言宏定义相关
写好C语言,漂亮的宏定义很重要,使用宏定义可以防止出错,提高可移植性,可读性,方便性 等等.下面列举一些成熟软件中常用得宏定义......1,防止一个头文件被重复包含#ifndef COMDEF_H# ...
- jQuery moblie 配合jQuery 实现移动端下拉刷新
<script type="text/javascript" src="http://bj.jiaju001.com/static/js/jquery-1.9.0. ...
- [Java]java反射随笔
类是面向对象的灵魂,一切事物都可以以类来抽象. 在java使用过程中,我们可能会经常用到一个反射的知识,只是别人都封装好的,如jdbc的加载驱动类有一句Class.for(“…jdbc…”).newI ...
- ARM Linux bootloader笔记
.text //指定了后续编译出来的内容放在代码段[可执行] .global //告诉编译器后续跟的是一个全局可见的名字[可能是变量,也可以是函数名] _start /*函数的其实地址,也是编译.链接 ...
- Scala中的类和对象
类的定义 使用class定义 类的字段 在类中使用var,val定义字段 类的方法 scala中,使用var定义字段默认提供setter和getter方法对应名称为 value_= 和value /* ...
- Jedis操作Redis数据库
添加Maven依赖: <dependencies> <!-- 单元测试 --> <dependency> <groupId>junit</grou ...
- 关于Object[]数组强转成Integer[]类型的数组.
为什么不能由Object[]数组强转成Integer[]数组. Object[] ins= { new Integer(0), new Integer(1), new Integer(2), new ...
- 【贪心+一点小思路】Zoj - 3829 Known Notation
借用别人一句话,还以为是个高贵的dp... ... 一打眼一看是波兰式的题,有点懵还以为要用后缀表达式或者dp以下什么什么的,比赛后半阶段才开始仔细研究这题发现贪心就能搞,奈何读错题了!!交换的时候可 ...
- hdu 1195 广度搜索
这题我们可以用优先队列,每次弹出队列中操作次数最少的一个,那么当找到匹配数时,该值一定是最优的.需要注意的时,加个vi[]数组,判读当前数是否已经存在于队列中.我做的很烦啊~~~ #include&l ...
- hostname
http://www.linuxidc.com/Linux/2014-11/109238.htm