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

#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. centos7 docker 安装 zookeeper 3.4.13 集群

    假设三台主机的ip分别为: 主机一:192.168.0.168 主机二:192.168.0.169 主机三:192.168.0.170 三台主机的安装步骤相似,以主机一为例: 1. 查找zookeep ...

  2. Udp -内部缓冲区

    1.每个socket关联了两个缓冲区,一个用于发送,一个用于接收. 2. 3.发送:(1)sendto()把数据放在sendbuf(缓冲区),通知os来取 (2)os在适当的时候过来取数据,并发到网络 ...

  3. SDUT OJ 数据结构实验之图论八:欧拉回路

    数据结构实验之图论八:欧拉回路 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  4. Hive内置函数和自定义函数的使用

    一.内置函数的使用 查看当前hive版本支持的所有内置函数 show function; 查看某个函数的使用方法及作用,比如查看upper函数 desc function upper; 查看upper ...

  5. 23.3Sum(三数和为零)

    Level:   Medium 题目描述: Given an array nums of n integers, are there elements a, b, c in nums such tha ...

  6. Windows远程连接CentOS图形化界面

    1.检查是否安装VNC rpm -q tigervnc tigervnc-server 2.安装安装X-Window # yum check-update # yum groupinstall &qu ...

  7. Android 系统特有的类介绍及使用

    1.Content类 在应用程序中Context的具体实现子类就是:Activity,Service,Application.可以把它理解成存储东西的仓库. 常用的上下文一般是类名.class或类名. ...

  8. C++_类继承4-访问控制protected

    public和private来控制对类成员的访问. 还存在另外一个访问类别,这种类别用关键字protected表示.protected和private相似,在类外只能用公有类成员来访问protecte ...

  9. leetcode 75 Sort Colors 计数排序,三路快排

    解法一:计数排序:统计0,1,2 的个数 时间复杂度:O(n) 空间复杂度:O(k)    k为元素的取值范围, 此题为O(1) class Solution { public: void sortC ...

  10. C# Task超时规则

    需要知道以下的知识 正规的骚操作:https://stackoverflow.com/questions/4238345/asynchronously-wait-for-taskt-to-comple ...