题意:

输入一个正整数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. nmon+python 基于AIX系统数据分析

    https://sourceforge.net/projects/pynmongraph/ github :https://github.com/madmaze/pyNmonAnalyzer nmon ...

  2. HTML入门归纳--JavaScript

    本人一直在从事.net的开发,界面都是采用的WPF,近期花了一个多月进行HTML前端的学习,在这里呢进行学习总结和归纳. 本系列将主要分为4个模块: 控件 样式 布局 JavaScript 根据多年W ...

  3. 【 SSH 配置参考】

    applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xm ...

  4. 作业2:go实现一个压测工具,具备upload功能

    作业:go实现压测工具,具备upload功能. upload内容是.tar.gz,使用http协议上传. 要求:upload的文件名,http目的地址灵活可配. deadline:2019.4.30

  5. 每天进步一点点------Altium Designer PCB设计规则中英对照

    Electrical(电气规则) Clearance:安全间距规则 Short Circuit:短路规则 UnRouted Net:未布线网络规则 UnConnected Pin:未连线引脚规则 Ro ...

  6. MySQL 整型

    MySQL中我们建表的时候,类型可以用bigint(20), 这是什么意思呢? 首先我们看bigint, MySQL的整型类型有这样几种: 类型      占用字节 tinyint        1 ...

  7. redis 基础操作教程

    1.linux 安装redis : Linux 下安装 下载地址:http://redis.io/download,下载最新稳定版本. 本教程使用的最新文档版本为 2.8.17,下载并安装: $ wg ...

  8. Nginx开始(自己使用,简单开始)

    Nginx 1.网址 2.安装 如果需要资料的话可以直接来下载进行下载 前提 sudo yum install yum-utils 云主机重启之后需要执行 nginx -c /etc/nginx/ng ...

  9. Vue - 实现双击显示编辑框;自动聚焦点击的显示框;点击编辑框外的地方,隐藏编辑框

    实现这三个功能的踩坑记录. 1. 需求 在Vue中,有一个input, 双击时编辑文本,点击该input节点外的其他地方,则取消编辑. 那么这里有三个要实现的地方 第一是双击显示编辑框. 第二是自动聚 ...

  10. php 发送手机验证码

    嗯哼,做为一个好的程序猿,一定要给顾客爸爸剁手的时候,充分的告诉他,你剁完手了,所以不只有邮件通知还要有手机短信的通知,今天就来写一下php发送验证码 1.首先我就写了几个个方法,因为配置在后台,直接 ...