时间限制
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. a code snip

    import java.util.ArrayList; import java.util.HashMap; import java.util.regex.Matcher; import java.ut ...

  2. 关于hkcmd.exe造成的和Eclipse之间热键冲突

    可能是自己新买的笔记本比较强大,显卡也比较牛叉.当使用一些常用的Eclipse快捷键的时候Eclipse本身没有反应,反而显示器有了反应. 经常用的Eclispse中的快捷键Ctrl+Alt+↑ 和C ...

  3. https抓包判断证书问题

    openssl s_client -connect 61.135.250.130:443这个是reg.163.com的 tcpdump 也可

  4. (转)C#模拟键盘鼠标事件

    原文 1.模拟键盘事件System.Windows.Forms.SendKeys以下是   SendKeys   的一些特殊键代码表.     键   代码       BACKSPACE   {BA ...

  5. MongoDB - Introduction to MongoDB, Documents

    MongoDB stores data records as BSON documents. BSON is a binary representation of JSON documents, th ...

  6. 学习IT技术的技巧

    怎样学习一个知识A? (1).为什么需要A?  (*) (2).什么是A?  (*) (3).怎么使用A[最简答的]?  (*) (4).使用A时注意的问题?  (*) (5).A的应用领域. (6) ...

  7. oracle视图索引

    reate table fleet_header(  day date,name varchar2(20),  route_id number(5),fleet_id number(5)); crea ...

  8. KVC/KVO总结

    KVC(键值编码) 动态设置: setValue:属性值 forKey:属性名(用于简单路径) setValue:属性值 forKeyPath:属(用于复合路径,例如Person有一个Account类 ...

  9. jQuery中的getter和setter方法

    1.attr()方法是jQuery中用于HTML属性的getter/setter.一个相关函数是removeAttr(). 2.css()方法和attr()方法很类似,只是css()方法作用于元素的c ...

  10. java计时器

    //用于计时,要求xx秒后开始发送短信,短信之间间隔xx秒 public static Date dateOperateBySecond(Date date,int second){ Calendar ...