反正知道了就是知道,不知道也想不到,很快

#include <cstdio>
#include <cstdlib>
#include <vector> using namespace std; inline void print_prime_k(long long p, long long k) {
printf("%lld", p);
if (k > ) {
printf("^%lld", k);
}
} int main() {
long long n, on;
scanf("%lld", &n);
on = n;
vector<long long> ps;
vector<long long> count; long long i = ;
long long last = ;
while (n > ) {
while (n % i == ) {
n = n/i;
if (i != last) {
ps.push_back(i);
count.push_back();
last = i;
}
count.back()++;
}
i++;
} int len = ps.size();
if (len > ) {
printf("%lld=", on);
print_prime_k(ps[], count[]);
} else {
printf("%lld=%lld", on, on);
}
for (int i=; i<len; i++) {
printf("*");
print_prime_k(ps[i], count[i]);
}
system("pause");
return ;
}

考虑输入是1的情况输出要为1=1

PAT 1059. Prime Factors的更多相关文章

  1. PAT 1059 Prime Factors[难]

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

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

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

  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. 决策树--Python

    决策树 实验集数据: #coding:utf8 #关键词:决策树(desision tree).特征选择.信息增益(information gain).香农熵.熵(entropy).经验熵(H(D)) ...

  2. c语言数据结构学习心得——数据结构基本概念

    1.数据>数据元素>数据项      数据的基本单位是数据元素,数据元素的基本单位是数据项 2.运算的定义->针对逻辑结构 集合:同属于一个集合,无其他关系.(数学上的集合) 线性结 ...

  3. Ajax轮询 select循环输出

    弹出层 <include file="Pub:header"/> <style> .del{color:red} .addname{color:#337ab ...

  4. c#优秀文章

    文件传输示例]C# WinForm WebSocket (非浏览器):http://bbs.cskin.net/thread-4431-1-1.html NanUI for Winform发布,让Wi ...

  5. sharepoint_study_4

    描述:如何向sharepoint自定义列表,新建(编辑)页面的网站栏后,添加一个快捷方式? 如图示: 解决: 1.在SharePoint Designer中打开该自定义列表 2.右键NewForm.a ...

  6. Covering(矩阵快速幂)

    Bob's school has a big playground, boys and girls always play games here after school.  To protect b ...

  7. linux下安装软件的方法(mariadb)

    一.方式 1. rpm (不推荐使用) 2. yum 安装(非常方便快捷) 3. 编译安装(需要自定制的时候才使用) 二.技术栈 #闭源收费的技术栈: svn + java + apache(web服 ...

  8. get 与 post 区别

    Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...

  9. c语言实现队列的基本操作

    话不多说,直接代码 #include"stdio.h" #include"stdlib.h" typedef struct QNode{ int date; s ...

  10. Nginx设置日志分割方法

    目标:nginx cronolog日志分割配置文档,每分钟分割一次NGINX访问日志. 大体步骤如下: 1.nginx日志配置 access_log /var/log/nginx/access.log ...