时间限制
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:

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)的更多相关文章

  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. json2使用方法

    例子1: //直接声明json数据结构 var myJSONObject = {"bindings": [ {"ircEvent": "PRIVMSG ...

  2. learning nodejs 1 - stream.pipe

    a simple http server using inner http module. var http = require('http'); var fs = require('fs'); // ...

  3. 开发一个struts2的实例

    前面一篇博客(实现struts2框架)带大家对基于mvc业务流程熟悉了一下,现在我们就用对mvc实现最好的框架struts2来开发一个应用实例.虽然现在MyEclipse8.5以上版本已经开始支持St ...

  4. C语言有关数组的几点

    动态大小数组 先来看一段代码: ; int a[n]; int i; ;i<n;i++) { a[i]=i; printf("%d\n",a[i]); } 我在声明数组a时, ...

  5. 【安卓面试题】在一个Activity启动另一个Activity和在Service中启动一个Activity有什么区别

    在Activity中可以直接使用Intent启动另一个Activity 显式Intent intent = new Intent(context, activity.class) 隐式 Intent ...

  6. 1045 | error connecting to master 'slave_user@192.168.0.75:3306' - retry-time: 6

    mysql 主从复制问题整理   问题:      1045 | error connecting to master 'slave_user@192.168.0.75:3306' - retry-t ...

  7. C#算法基础之希尔排序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. 在Delphi中,关于数组名称

    动态数组数组名代表的是第一个元素的内存地址. 静态数组名称代表的是数组第一个元素的内存位置, 而不是数组第一个元素的内存地址. 但对于静态数组,在某些情况下编译器可能会自动取数组地址,如: funct ...

  9. Ssqlserver 关于Grouping sets

    sqlserver2008之后引入Grouping sets是group by的增强版本,Grouping sets 在遇到多个条件时,聚合是一次性从数据库中取出所有需要操作的数据,在内存中对数据库进 ...

  10. 关于《Swift开发指南》背后的那些事

    时间轴(倒叙)2014年8月底在图灵出版社的大力支持下,全球第一本全面.系统.科学的,包含本人多年经验的呕心沥血之作<Swift开发指南>(配有同步视频课程和同步练习)全线重磅推出2014 ...