PAT 1059 Prime Factors[难]
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 = p1k1×p2k2×⋯×pmkm.
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
题目大意:给出一个数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[难]的更多相关文章
- PAT 1059. Prime Factors (25) 质因子分解
题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...
- PAT 1059. Prime Factors
反正知道了就是知道,不知道也想不到,很快 #include <cstdio> #include <cstdlib> #include <vector> using ...
- 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 ...
- 1059 Prime Factors (25分)
1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ...
- PAT 甲级 1059 Prime Factors
https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488 Given any positive int ...
- 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 ...
- 1059. Prime Factors (25)
时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...
- 1059 Prime Factors(25 分)
Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
随机推荐
- phpstrom xdebug wamp调试配置文档
下载并安装phpstorm,下载地址如下 http://download-cf.jetbrains.com/webide/PhpStorm-9.0.2.exe 安装完成后,完成注册,注册方法如下 ...
- zend Studio10.6.2 下载
http://www.th7.cn/Program/php/201409/286788.shtml
- PHP高并发的解决方案
这几天面试,被问到这样一个问题:如何解决大流量的高并发问题.起初不知所措,在查阅相关资料,以及网上大牛们的解答之后,总结出以下几点: 1.服务器,如果同时访问量超过10W的话,需要采用专用服务器来承载 ...
- 使用jQuery模拟Google的自动提示效果
注意: 1.本功能使用SqlServler2000中的示例数据库Northwind,请打SP3或SP4补丁:2.请下载jQuery组件,河西FTP中有下载:3.本功能实现类似Google自动提示的效果 ...
- Linux中安装配置hadoop集群
一. 简介 参考了网上许多教程,最终把hadoop在ubuntu14.04中安装配置成功.下面就把详细的安装步骤叙述一下.我所使用的环境:两台ubuntu 14.04 64位的台式机,hadoop选择 ...
- 面向对象分析和设计(OOA/D)
UML不是OOA/D,也不是方法,它仅仅是一种图形表示法(表示的是OOA/D的想法),我们将在OOA/D中应用UML:分析,就是理解客户脑子中的概念,跟客户来沟通,分析出专业术语:设计,对分析出来的专 ...
- 用newInstance与用new是区别的
用newInstance与用new是区别的,区别在于创建对象的方式不一样,前者是使用类加载机制,那么为什么会有两种创建对象方式?这个就要从可伸缩.可扩展,可重用等软件思想上解释了.Java中工厂模式经 ...
- ChemDraw中化学信息怎么通过Excel搜索
用户可以通过ChemDraw for Excel插件功能在Office Excel中建立ChemOffice菜单将ChemOffice和Excel结合使用,使用电子表格的最大优势之一就是可以清晰查看并 ...
- Microsoft Word、Excel、PowerPoint转Pdf
Worksheet.ExportAsFixedFormat Method Mark: The ExportAsFixedFormat method is used to publish a workb ...
- Maven的Settings.xml配置文件解释
该配置用于单用户配置和全局配置, 单用户配置默认存放于 ${user.home}/.m2/目录中. 全局配置默认存放于Maven安装目录下面的conf目录中. 这两个默认的位置都可以修改. <? ...