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. 第二百四十九节,Bootstrap附加导航插件

    第二百四十九节,Bootstrap附加导航插件 学习要点: 1.附加导航插件 本节课我们主要学习一下 Bootstrap 中的附加导航插件 一.附加导航 注意:此插件要使用 bootstrap3.0. ...

  2. 【BZOJ】1492: [NOI2007]货币兑换Cash(cdq分治)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1492 蒟蒻来学学cdq神算法啊.. 详见论文 陈丹琦<从<Cash>谈一类分治算法 ...

  3. 【NOIP模拟题】“与”(位运算)

    因为是与运算,所以我们可以贪心地每次找最高位的,将他们加入到新的序列中,然后每一次在这个新的序列继续找下一个位. 然后最后序列中任意两个的与运算的值都是一样的且是最大的. #include <c ...

  4. Unity3D 物体移动方式总结(转)

    1. 简介 在unity3d中,有多种方式可以改变物体的坐标,实现移动的目的,其本质是每帧修改物体的position. 2. 通过Transform组件移动物体 Transform 组件用于描述物体在 ...

  5. 指针*pbuffer和getchar 读取字符串

    在C语言入门教材里看到这一段代码,没看懂是什么意思.char buffer[10];char *pbuffer = buffer;while( (*pbuffer++ = getchar() )!= ...

  6. vue2.0中子组件通过v-modal改变父组件中的值

    父组件代码: <template lang="pug"> div p this is father child(v-model="data") &l ...

  7. python中的各种符号

    在这里所作的是将所有的 Python 符号和关键字列出来,这些都是值得掌握的重点. 关键字  and  del  from  not  while  as  elif  global ...

  8. LAMP集群项目

    vi /etc/sysconfig/network 一.安装硬件环境(安装虚拟机) 1.安装VMware步骤 1.修改网卡配置 vi /etc/sysconfig/network-scripts/if ...

  9. LAMP集群项目四 安装apache、php及其插件

    rpm -qa httpd* 查看是否有apache rpm -e httpd-2.2.22.2  卸载该文件,如果不让卸载,则加参数:--nodeps 不做软件中的依赖检查 ./configure ...

  10. VMware虚拟机下安装CentOS7.0超详细图文教程

    1.本文说明: 官方的第一个文本档案.也就是0_README.txt,大概意思是这样(渣翻译,但是大概意思还是有的). CentOS-7.0-1406-x86_64-DVD.iso:这个镜像(DVD ...