https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488

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

代码:

#include <bits/stdc++.h>
using namespace std; long int P;
int prime[500010]; int main() {
memset(prime, 1, sizeof(prime));
for(int i = 2; i * i <= 500010; i ++)
for(int j = 2; j * i < 500010; j ++)
prime[j * i] = 0;
scanf("%ld", &P); printf("%ld=", P);
if(P == 1) printf("1"); bool First = false;
for(int i = 2; P >= 2; i ++) {
int cnt = 0, flag = 0;
while(prime[i] && P % i == 0) {
cnt ++;
P /= i;
flag = 1;
}
if(flag) {
if(First)
printf("*");
printf("%d", i);
First = true;
}
if(cnt > 1)
printf("^%d", cnt);
}
return 0;
}

  素数表! Get

PAT 甲级 1059 Prime Factors的更多相关文章

  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. PAT甲级——A1059 Prime Factors

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

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

  4. PAT 1059 Prime Factors[难]

    1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ...

  5. 1059 Prime Factors (25分)

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

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

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

  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 分)

    题意: 输入一个正整数N(范围为long int),输出它等于哪些质数的乘积. trick: 如果N为1,直接输出1即可,数据点3存在这样的数据. 如果N本身是一个质数,直接输出它等于自己即可,数据点 ...

随机推荐

  1. Python学习 :多线程 --- 锁

    多线程 什么是锁? - 锁通常被用来实现对共享资源的同步访问. - 为每一个共享资源创建一个Lock对象,当你需要访问该资源时,调用acquire方法来获取锁对象(如果其它线程已经获得了该锁,则当前线 ...

  2. 适合初学Altium Designer的教学视频

    以下推荐的我都亲自看过,个人感觉确实不错,可以有助于了解流程,以及一些设计规范 首先是凡亿的PCB教学,贵是贵了点,不过也有免费的,讲解的很详细,而且还有专门的群,610359270 http://w ...

  3. Redis数据结构总结

    Redis 字符串(String) SET runoobkey redis GET runoobkey Redis 哈希(Hash) Redis hash 是一个string类型的field和valu ...

  4. IDEA常见错误解决

    tomcat控制台乱码 在tomcat的edit configurations里加入参数:-Dfile.encoding=UTF-8   导入的项目在重写时报 @Override is not all ...

  5. 20155302 实验三 敏捷开发与XP实践

    20155302 实验三 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验内容及步骤 (一)编码标准 在IDEA中使用工具(Code->Reformate Code)把代码重 ...

  6. 20155310 2016-2017-2《Java程序设计》课堂实践补交

    20155310 2016-2017-2<Java程序设计>课堂实践补交 第九周 程序设计中临时变量的使用 public class linshibianliang { public st ...

  7. P1546 最短网络(codevs | 2627村村通)

    P1546 最短网络 Agri-Net 题目背景 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场.当然,他需要你的帮助. 题目描述 约翰已经给他的农场安排了一 ...

  8. Walle代码发布

    一.概述 Walle 一个web部署系统工具,配置简单.功能完善.界面流畅.开箱即用!支持git.svn版本管理,支持各种web代码发布,PHP,Python,JAVA等代码的发布.回滚,可以通过we ...

  9. STM32运行FreeRTOS出现prvTaskExitError错误死机

    文件port.c prvTaskExitError();任务退出错误,一个可能在任务里面写了return,另一个可能任务切换退出问题,入栈和出栈的时候出了问题. static void prvTask ...

  10. Git生成多个ssh key

    在实际的工作中, 有可能需要连接多个远程仓库, 例如我想连接私有仓库.GitLab官网.GitHub官网, 那么同一台电脑就要生成多个ssh key: ssh-keygen -t rsa -C &qu ...