【PAT甲级】1059 Prime Factors (25 分)
题意:
输入一个正整数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 分)的更多相关文章
- 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 ...
- PAT 1059. Prime Factors (25) 质因子分解
题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...
- 1059. Prime Factors (25)
时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
随机推荐
- 使用python实现冒泡、选择、插入基础排序
冒泡排序 依次比较相邻两元素,若前一元素大于后一元素则交换之,直至最后一个元素即为最大: 然后重新从首元素开始重复同样的操作,直至倒数第二个元素即为次大元素: 依次类推.如同水中的气泡,依次将最大或最 ...
- 【网易官方】极客战记(codecombat)攻略-地牢-逃脱
关卡连接: https://codecombat.163.com/play/level/breakout 矮人正在追你,前方道路已被堵死. 简介: 通过攻击 "弱门" 释放盟友,这 ...
- MongoDB_05_更新和删除
文档的更新和删除 更新文档的方法: db.collection.update(query,update,options) //或 db.collection.update( <query> ...
- n个点的最长公共子串(别人的模板) poj 3080
没有理解代码.单纯记模板 题意:找最长的公共字串,长度相同就找字典序最小的(这一点wa了我13遍!!!)题解:kmp或者直接暴力列举当公共子串长度小于3时,有特判 #include<map> ...
- 前端知识之html
html介绍 web服务器的本质 import socket sk=socket.socket() sk.bind(('127.0.0.1'.8080)) sk.listen(5) while Tru ...
- go key-value缓存go-cache实现
Cache类型 Cache封装了一个cache类型,cache类型的参数解析: 1.defaultExpiration time.Duration 每个键值的默认过期时间. 2.items map[s ...
- HNOI2019 题解
题目排序不是我做题的顺序也不是试题顺序. 多边形 首先要知道终止态是所有边都指向了 \(n\) 号节点. 那么我们如果每一步都让 \(n\) 的度数 +1 那一定是最优的,显然可以办到. 那么可以从与 ...
- python操作oracle完整教程
1. 连接对象 操作数据库之前,首先要建立数据库连接.有下面几个方法进行连接. >>>import cx_Oracle>>>db = cx_Oracle.co ...
- 【WPF学习】第十四章 事件路由
由上一章可知,WPF中的许多控件都是内容控件,而内容控件可包含任何类型以及大量的嵌套内容.例如,可构建包含图形的按钮,创建混合了文本和图片内容的标签,或者为了实现滚动或折叠的显示效果而在特定容器中放置 ...
- CSS - div中的文字不换行,超出宽度就用省略号表示
问题 过多的文字会把盒子撑开,造成布局错乱. 解决 .card-title { white-space: nowrap; text-overflow: ellipsis; overflow: hidd ...