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 = p​1​​​k​1​​​​×p​2​​​k​2​​​​×⋯×p​m​​​k​m​​​​.

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 = p​1​​^k​1​​*p​2​​^k​2​​**p​m​​^k​m​​, where p​i​​'s are prime factors of N in increasing order, and the exponent k​i​​ is the number of p​i​​ -- hence when there is only one p​i​​, k​i​​ is 1 and must NOT be printed out.

Sample Input:

97532468

Sample Output:

97532468=2^2*11*17*101*1291

题目大意:给出一个数n,在long int内,给出其素数分解,如果某个素数有多个是其分数,那么用指数形式表示;如果n本身就是素数,那么指数1不输出。

//猛一看,自己就想到了是建立大数素数表,但是具体操作我似乎不大会。以前看过,但是不知道具体怎么写了。

//自己写了一点点就蔫了。
#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stdio.h>
#include <map>
#include<cmath>
using namespace std;
//需要先求出long int内所有的素数。
//但是有一个问题,如果是long int,那么我定义多大的数组呢?要么用向量?
#define maxn 1e7
int a[maxn];
vector<int> vt;
bool isPrime(int n){
int m=sqrt(n);
for(int i=;i<=n;i++){
if(n%i==)return false;
}
return true;
} void getPrime(int n){
for(int i=;i<=n;i++){
if(a[i]==){
if(isPrime(i)){
a[i]=;
for(int j=i*i;j<=n;j=j*i){//是按照立方去标记吗? }
}
}
}
}
int main()
{
long int n;
cin>>n;
getPrime(n);
return ;
}

下面是柳神的代码:

1.原来求大数内素数还可以这么求,学习了。

2.并且在判断时可以边判断边输出。

PAT 1059 Prime Factors[难]的更多相关文章

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

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

  2. PAT 1059. Prime Factors

    反正知道了就是知道,不知道也想不到,很快 #include <cstdio> #include <cstdlib> #include <vector> using ...

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

  4. 1059 Prime Factors (25分)

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

  5. PAT 甲级 1059 Prime Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488 Given any positive int ...

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

  7. 1059. Prime Factors (25)

    时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...

  8. 1059 Prime Factors(25 分)

    Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...

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

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

随机推荐

  1. MapReduce的InputFormat过程的学习

    转自:http://blog.csdn.net/androidlushangderen/article/details/41114259 昨天经过几个小时的学习,把MapReduce的第一个阶段的过程 ...

  2. Web项目的WEB-INF目录使用说明以及重定向与转发

    写这篇文章的原因是看到了Tomcat下面的Webapps下面的,就想看一下. 总结一下这篇文章的内容: WEB-INF下面的内容都是只能由服务器级别才能访问,客户端并不能访问.什么是客户端级别?什么是 ...

  3. MapReduce与Hadoop之比较

    MapReduce与Hadoop之比较 Hadoop是Apache软件基金会发起的一个项目,在大数据分析以及非结构化数据蔓延的背景下,Hadoop受到了前所未有的关注. Hadoop是一种分布式数据和 ...

  4. php如何判断两个时间的时间差

    $time1=2011-11-11 11:11:11$time2=2016-12-10 16:58:13 代码: if(abs(strtotime($time2)-strtotime($time1)) ...

  5. 编程之美 set 16 拈游戏分析(1)

    题目 N 个石头排成一行, 每块石头有固定的位置和编号, 两个玩家依次取石头, 每个玩家可以取其中的任一块石头, 或者相邻的两个石头. 石头在游戏过程中不能移位, 最后将剩下的石头依次取光的玩家获胜 ...

  6. iOS开发之-- textview 光标起始位置偏移

    使用textview的时候,会发生光标偏移的情况,其实是因为iOS7里导航栏,状态栏等有个边缘延伸的效果在. 把边缘延伸关掉就好了.代码如下 //取消iOS7的边缘延伸效果(例如导航栏,状态栏等等) ...

  7. 数据库为什么要用B+树结构--MySQL索引结构的实现(转)

    B+树在数据库中的应用 { 为什么使用B+树?言简意赅,就是因为: 1.文件很大,不可能全部存储在内存中,故要存储到磁盘上 2.索引的结构组织要尽量减少查找过程中磁盘I/O的存取次数(为什么使用B-/ ...

  8. 【BZOJ2525】[Poi2011]Dynamite 二分+树形DP

    [BZOJ2525][Poi2011]Dynamite Description Byteotian Cave的结构是一棵N个节点的树,其中某些点上面已经安置了炸.药,现在需要点燃M个点上的引线引爆所有 ...

  9. 如何使用iOS 开发证书 和 Profile 文件

    如果你想在 iOS 设备(iPhone/iPad/iTouch)上调试, 需要有 iOS 开发证书和 Profile 文件. 在你拿到这两个文件之后,该如何使用呢? 证书使用说明: 1.  iOS 开 ...

  10. 几种压缩方式:zlib

    zlib:zlib.h http://www.zlib.net/manual.html 编译时加 -lz ZEXTERN int ZEXPORT compress OF((Bytef *dest, u ...