PAT 1059. Prime Factors
反正知道了就是知道,不知道也想不到,很快
#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的更多相关文章
- PAT 1059 Prime Factors[难]
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ...
- PAT 1059. Prime Factors (25) 质因子分解
题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...
- 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 ...
- 1059 Prime Factors (25分)
1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ...
- PAT 甲级 1059 Prime Factors
https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488 Given any positive int ...
- 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 ...
- 1059. Prime Factors (25)
时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...
- 1059 Prime Factors(25 分)
Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
随机推荐
- 华为敏捷DevOps实践:产品经理如何开好敏捷回顾会议
大家好,我是华为云DevCloud项目管理服务的产品经理 恒少:) 作为布道师和产品经理,出差各地接触客户是常态,经常和华为云的客户交流.布道.技术沙龙,但是线下交流,覆盖的用户总还是少数.我希望借助 ...
- CodeForces - 233A Perfect Permutation
A. Perfect Permutation time limit per test: 2 seconds memory limit per test: 256 megabytes input: st ...
- CentOS中源码编译安装Nginx
1.从官网通过wget命令将Nginx源码包下载到Linux上 Nginx下载页面:http://nginx.org/en/download.html 2.在Linux上安装需要依赖的环境 yum ...
- Qt 学习之路 2(47):视图选择
Qt 学习之路 2(47):视图选择 豆子 2013年3月28日 Qt 学习之路 2 34条评论 选择是视图中常用的一个操作.在列表.树或者表格中,通过鼠标点击可以选中某一项,被选中项会变成高亮或者反 ...
- windows cmd下创建虚拟环境virtualenv
一:虚拟环境virtualenv 如果在一台电脑上, 想开发多个不同的项目, 需要用到同一个包的不同版本, 如果使用上面的命令, 在同一个目录下安装或者更新, 新版本会覆盖以前的版本, 其它的项目就无 ...
- 005 Genymotion模拟器的使用和逍遥模拟器的使用
1.Genymotion模拟器 (1)Genymotion Device Manager的图标 重启软件Android Studio后,选择菜单栏“View--Toolbar”,让工具栏显示出来,可以 ...
- JAVA数据结构--ArrayList动态数组
在计算机科学中,动态数组,可扩展数组,可调整数组,动态表,可变数组或数组列表是一种随机存取可变大小列表数据结构,允许添加或删除元素.它提供许多现代主流编程语言的标准库.动态数组克服了静态数组的限制,静 ...
- 015-GenericEncodingFilter模板【解决全局乱码】
package ${enclosing_package}; import java.io.IOException; import java.io.UnsupportedEncodingExceptio ...
- 8086实时时钟实验(二)——《x86汇编语言:从实模式到保护模式》读书笔记06
上次我们说了代码,这次我们说说怎样看到实验结果. 首先编译源文件(我的源文件就在当前路径下,a盘和c盘在上一级目录下): nasm -f bin c08_mbr.asm -o c08_mbr.bin ...
- Win10内置应用恢复初始状态
和Win8/Win8.1相同,Win10也内置了很多默认Windows应用,比如计算器.天气.人脉.Groove音乐.电影和电视.邮件和日历.Edge浏览器等.一般情况下,这些应用不会有太大的问题,但 ...