时间限制
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. Java SE ---算术运算符

    算术运算符:(加)+,(减)-,(乘)*,(除)/,(求余)%,自增自减 一,算数运算符:当有若干个变量参与运算时,结果类型取决于这些变量中表示范围最大的那个变量类型.如果参加运算的变量中有整型int ...

  2. ASP.NET MVC 下载列表

    在ASP.NET WebForm里要想网站某个文件夹的文件列出来供用户下载似乎很简单,WebForm帮你做了很多事,只需要在Html文件里写: <a href="~/download/ ...

  3. ASP.NET MVC and jqGrid 学习笔记 6-增删改操作

    程序结构: Member.cs CRUD.cshtml CRUD.js HomeController 一.Model public class Member { [Key] public int No ...

  4. Linux 通过 load average 判断服务器负载情况

    Linux中load average判断服务器负载情况 转载文章 http://www.111cn.net/sys/linux/56003.htm 写的比较详细,推荐看看.

  5. oracle 自增列设置

    序列 create sequence sq_1 minvalue maxvalue start increment cache ; 触发器 create or replace trigger 触发器名 ...

  6. JMS笔记(一)

    1.jms概念 Java Message Service为 Java程序提供一种访问企业消息系统的方法,JMS应用由JMS生产者.JMS Provider.JMS消费者构成 1.1. 一条Messag ...

  7. HTML <base> 标签的 target 属性 —— <base target="_blank" />

    为页面上所有链接规定默认目标: <head> <base target="_blank" /> </head> <body> < ...

  8. LeetCode 338

    Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the ...

  9. 历经曲折的freescale

    从来没有想到自己在大学最信任的队友会突然放弃,,为了这个,,我可以说放弃了很多,,这几天可以我也不知道怎么办了,,我想不通的是为什么可以这样,为什么可以这么不负责任,,为什么这么自私,,这些我永远都不 ...

  10. Java多线程原理

    学过Java的人都知道,Java是少数的集中支持多线程的语言之一,大多数的语言智能运行单独的一个程序块,无法同时运行不同的多个程序块,Java的多线程机制弥补了这个缺憾,他可以让不同的程序块一起运行, ...