时间限制
50 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
HE, Qinming

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:

  1. 97532468

Sample Output:

  1. 97532468=2^2*11*17*101*1291
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<vector>
  4. using namespace std;
  5. int main()
  6. {
  7. int n,i,j;
  8. vector<int> vv;
  9. for(i= ;i<=;i++)
  10. {
  11. bool is = true;
  12. for(j=;j<=sqrt(i*1.0);j++)
  13. {
  14. if(i % j == )
  15. {
  16. is = false;
  17. break;
  18. }
  19. }
  20. if(is) vv.push_back(i);
  21. }
  22. while(scanf("%d",&n)!=EOF)
  23. {
  24. printf("%d=",n);
  25. bool fir = true;
  26. if(n == ) printf("");
  27. else
  28. {
  29. i = ;
  30. while(n != )
  31. {
  32. if(n % vv[i] == )
  33. {
  34. int tem = ;
  35. while(n % vv[i] == )
  36. {
  37. ++tem;
  38. n = n / vv[i];
  39. }
  40.  
  41. if(fir)
  42. {
  43. printf("%d",vv[i]);
  44. fir = false;
  45. }
  46. else
  47. {
  48. printf("*%d",vv[i]);
  49. }
  50.  
  51. if(tem > )
  52. {
  53. printf("^%d",tem);
  54. }
  55. }
  56.  
  57. ++i;
  58. }
  59. }
  60.  
  61. printf("\n");
  62. }
  63. return ;
  64. }

1059. Prime Factors (25)的更多相关文章

  1. 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 ...

  2. 1059 Prime Factors (25分)

    1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ...

  3. PAT 1059. Prime Factors (25) 质因子分解

    题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...

  4. 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 ...

  5. PAT甲题题解-1059. Prime Factors (25)-素数筛选法

    用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...

  6. PAT (Advanced Level) 1059. Prime Factors (25)

    素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

  7. 【PAT甲级】1059 Prime Factors (25 分)

    题意: 输入一个正整数N(范围为long int),输出它等于哪些质数的乘积. trick: 如果N为1,直接输出1即可,数据点3存在这样的数据. 如果N本身是一个质数,直接输出它等于自己即可,数据点 ...

  8. pat1059. Prime Factors (25)

    1059. Prime Factors (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...

  9. PAT 1059 Prime Factors[难]

    1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ...

随机推荐

  1. C语言宏定义相关

    写好C语言,漂亮的宏定义很重要,使用宏定义可以防止出错,提高可移植性,可读性,方便性 等等.下面列举一些成熟软件中常用得宏定义......1,防止一个头文件被重复包含#ifndef COMDEF_H# ...

  2. jQuery moblie 配合jQuery 实现移动端下拉刷新

    <script type="text/javascript" src="http://bj.jiaju001.com/static/js/jquery-1.9.0. ...

  3. [Java]java反射随笔

    类是面向对象的灵魂,一切事物都可以以类来抽象. 在java使用过程中,我们可能会经常用到一个反射的知识,只是别人都封装好的,如jdbc的加载驱动类有一句Class.for(“…jdbc…”).newI ...

  4. ARM Linux bootloader笔记

    .text //指定了后续编译出来的内容放在代码段[可执行] .global //告诉编译器后续跟的是一个全局可见的名字[可能是变量,也可以是函数名] _start /*函数的其实地址,也是编译.链接 ...

  5. Scala中的类和对象

    类的定义 使用class定义 类的字段 在类中使用var,val定义字段 类的方法 scala中,使用var定义字段默认提供setter和getter方法对应名称为 value_= 和value /* ...

  6. Jedis操作Redis数据库

    添加Maven依赖: <dependencies> <!-- 单元测试 --> <dependency> <groupId>junit</grou ...

  7. 关于Object[]数组强转成Integer[]类型的数组.

    为什么不能由Object[]数组强转成Integer[]数组. Object[] ins= { new Integer(0), new Integer(1), new Integer(2), new ...

  8. 【贪心+一点小思路】Zoj - 3829 Known Notation

    借用别人一句话,还以为是个高贵的dp... ... 一打眼一看是波兰式的题,有点懵还以为要用后缀表达式或者dp以下什么什么的,比赛后半阶段才开始仔细研究这题发现贪心就能搞,奈何读错题了!!交换的时候可 ...

  9. hdu 1195 广度搜索

    这题我们可以用优先队列,每次弹出队列中操作次数最少的一个,那么当找到匹配数时,该值一定是最优的.需要注意的时,加个vi[]数组,判读当前数是否已经存在于队列中.我做的很烦啊~~~ #include&l ...

  10. hostname

    http://www.linuxidc.com/Linux/2014-11/109238.htm