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 ...
随机推荐
- yum及RPM安装
yum及RPM安装 基本说明: 1.yum相当于windows上面的360软件中心 2.yum是redhat系列发行版的软件安装命令 debian系统用的是apt-get 3.yum安装软件的来源得存 ...
- xunsearch
xunsearch 1.wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2 2.解压 tar -jxvf xuns ...
- css文章
前端HTML-CSS规范:https://yq.aliyun.com/articles/51487 jQuery+d3绘制流程图:https://blog.csdn.net/zitong_ccnu/a ...
- 7、C++枚举类型
7.枚举类型 C++的enum工具提供了另一种创建符号常量的方式,这种方式可以代替const.它还允许定义新类型,但必须按严格的限制进行.使用enum的语法与使用结构的相似. enum spectru ...
- 利用CountDownLatch和Semaphore测试案例
package com.cxy; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CountDo ...
- javascrip 中排序的函数怎么理解
其中s是数组[888,2222,9,4]:我不明白sort函数中参数是如何作用的,function中的a和b又是干什么的? 那个function的作用就是比较两个数的大小用的,然后返回结果的正负作为排 ...
- 【floyd】【bitset】洛谷 P1841 [JSOI2007]重要的城市 题解
bitset玄学完美优化复杂度? 题目描述 参加jsoi冬令营的同学最近发现,由于南航校内修路截断了原来通向计算中心的路,导致去的路程比原先增加了近一公里.而食堂门前施工虽然也截断了原来通向计 ...
- VBS添加Windows登陆账号
Set o=CreateObject( "Shell.Users" ) Set z=o.create("test") z.changePassword &quo ...
- ecshop 模板机制
ECShop模板是基于smarty 文件名cls_template.php lib_main.php中的assign_template()会设置我们的网店的公共信息及网站设置:assign_dynam ...
- 企业DevOps构建 (一)
一,环境: tomcat 7.0.92 jenkins 1.658 maven mysql 5.5.23 mongodb 2.6.11 redis 4.0.12 01, 安装jenkins wge ...