题意:

输入一个正整数N(范围为long int),输出它等于哪些质数的乘积。

trick:

如果N为1,直接输出1即可,数据点3存在这样的数据。

如果N本身是一个质数,直接输出它等于自己即可,数据点4存在这样的数据。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int ans[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin>>n;
long long x=n;
int num=;
for(int i=;1ll*i*i<=n;++i){
if(x==)
break;
while(x%(1ll*i)==){
x/=1ll*i;
++ans[i];
++num;
if(x==)
break;
}
}
if(num==){
cout<<n<<"="<<n;
return ;
}
cout<<n<<"=";
int flag=;
for(int i=;i*i<=n;++i)
if(ans[i]){
if(flag)
cout<<"*";
cout<<i;
if(ans[i]>)
cout<<"^"<<ans[i];
flag=;
}
return ;
}

【PAT甲级】1059 Prime Factors (25 分)的更多相关文章

  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. 1059 Prime Factors (25分)

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

  3. PAT 甲级 1059 Prime Factors

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

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

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

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

  6. 1059. Prime Factors (25)

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

  7. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  8. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  9. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

随机推荐

  1. Mysql 函数定义及批量数据脚本

    零.说在前面 在定义函数之前 需要先将 log_bin_trust_function_creators 值设为开启,原因如下 在主从复制的两台Mysql服务器中,slaver会从master复制数据, ...

  2. hadoop学习笔记(九):mapReduce1.x和2.x

    一.MapReduce1.0的数据分割到数据计算的过程 MapReduce是我们再进行离线大数据处理的时候经常要使用的计算模型,MapReduce的计算过程被封装的很好,我们只用使用Map和Reduc ...

  3. code ELIFECYCLE 报错处理

    npm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! m-kbs-vip@1.2.12 toserver: `tua -p toserver`npm ERR ...

  4. Codeforces Round #598 (Div. 3) F. Equalizing Two Strings

    You are given two strings ss and tt both of length nn and both consisting of lowercase Latin letters ...

  5. sqli-libs(29(jspstudy)-31关)

    Less_29 Less-29: 需要用到jspstudy跟phpstudy   搭建jspstudy: sqli-labs-master文件夹下面还有tomcat文件,这才是真正的关卡,里面的jsp ...

  6. springboot1.5.9 整合单机版redis3.2.8

    redis是一种可基于内存也可基于持久话的日志型.key-value数据库.因为性能高,存储数据类型丰富等优势常被用作数据缓存. 我们利用spring-boot-autoconfiguration.j ...

  7. MYSQL实现分组排序并取组内第一条数据

    一.需要实现分组排序并且取组内状态优先级最高的数据 有一张这样的数据表, 需求是根据error_type分组然后取status最小的第一条数据 第一种写法: select t.* from ( sel ...

  8. Ubuntu系统备份还原教程

    一.备份 很多人有备份系统的习惯,以防系统挂.Windows下可以用DISM创建一个系统镜像,在Ubuntu下,我们可以使用squashfs-tools创建系统镜像. 准备工作 可启动LiveCD一份 ...

  9. SOA架构设计

    架构是—套构建系统的准则,通过这套准则,把—个复杂的系统划 分为一套更简单的子系统的集合,这些子系统之间保持相互独立,并与 整个系统保持一致,而且每—个子系统还可以继续细分下去,从而构成 —个企业级架 ...

  10. 喵星之旅-狂奔的兔子-centos7一键安装redmine

    一.安装环境 CentOS-7-x86_64-DVD-1908.iso 二.获取安装文件 从官网获取,在下载页面提供了多种安装,最下方是一键安装版本,里面有两种选择,一个是安装包,一个是虚拟机硬盘文件 ...