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. 002servlet生命周期以及有关servlet的各种知识

    4 Sevlet的生命周期(重点) 有关servlet的类有Servlet,HttpServlet以及GenericServlet. 其实我们要写一个Servlet只要写一个类去实现Servet就可以 ...

  2. 系统管理模块_岗位管理_改进_使用ModelDroven方案_套用美工写好的页面效果_添加功能与修改功能使用同一个页面

    改进_使用ModelDroven方案 @Controller @Scope("prototype") public class RoleAction extends ActionS ...

  3. Android无线测试之—UiAutomator UiScrollable API介绍五

    滑动区域校准常量设置与获取 一.校准概念 校准常量指的是:滑动操作坐标时的偏移量,用来取偏移比例 二.相关API 返回值 API 描述 double getSwipeDeadZonePercentag ...

  4. 将java项目发布到本地的linux虚拟机上

    1.首先安装虚拟机,这里就不介绍了. 2.然后要我下载了一个WinSCP用于windows和虚拟机之间的文件传输. 首先获得虚拟机的ip: 必须保持连接, 如果断开ip就是这样的 3.传输文件 将jd ...

  5. 在 Linux 下使用任务管理器

    有很多 Linux 初学者经常问起的问题,“Linux 有任务管理器吗?”,“怎样在 Linux 上打开任务管理器呢?” 来自 Windows 的用户都知道任务管理器非常有用.你可以在 Windows ...

  6. JAVA上百实例源码网站

    JAVA源码包1JAVA源码包2JAVA源码包3JAVA源码包4 JAVA开源包1 JAVA开源包2 JAVA开源包3 JAVA开源包4 JAVA开源包5 JAVA开源包6 JAVA开源包7 JAVA ...

  7. 非IE图片上传预览

    $("#uploadFiles").change(function (e) {                if (e.target.files) {               ...

  8. Arduino开发版学习计划--小车的行走

    小车的前进后退,左右转弯 代码如下 void motor(char pin,char pwmpin,char state,int val) { pinMode(pin, OUTPUT); ) { an ...

  9. vue兄弟组件传值

    vue中除了父子组件传值,父传子用props,子传父用$emit,有时候兄弟组件之间也需要传值 1. 先定义一个中间件,src下面新建self.js import Vue from 'vue'; le ...

  10. Code Forces 645C Enduring Exodus

    C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...