【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 ...
随机推荐
- chrome firefox浏览器屏蔽百度热搜
我是原文 操作 点击拦截元素,然后选择页面元素,添加
- docker 环境部署
docker 查看所有容器 docker ps -a docker 查看所有running 容器: docker ps docker 停止全部容器: docker stop $(docker ps ...
- 题解 SP5271 XOINC - A Coin Game
SP5271 XOINC - A Coin Game 双倍经验:P2964 [USACO09NOV]硬币的游戏A Coin Game O3做法(TLE):枚举i,j,k,即剩下i枚金币,上一轮选了j枚 ...
- js变量提升的坑
关于js变量提升 变量提升 在js函数内部是可以直接修改全局的变量的,个人感觉是不好的设计, 但是确实存在这个概念 原理: 先查看有没有函数变量bb 查看形参有没有bb 查看全局有没有bb 报错, 找 ...
- Mac下ssh远程无密码登录
入手Mac,对很多工具的使用都不太熟悉,这不,做web开发,登录远程服务器非常繁琐,想要去掉输入密码这个环节,找到网友的分享如下: http://www.cnblogs.com/shuaiwhu/ar ...
- Oracle 11G统计信息自动收集及调整
查询统计信息的收集所对应的task,以及当前状态 col CLIENT_NAME for a50col TASK_NAME for a20SELECT client_name, task_name, ...
- 1042B. Vitamins
Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set o ...
- tomcat安装成功以后进行测试步骤:
tomcat安装成功以后进行测试步骤: 编写测试页面: 进入Tomcat安装对应路径: E:\Tomcat\apache-tomcat-8.5.45\webapps\ROOT 创建:test.jsp ...
- 2019,.Net开发者的高光时刻
随着微软发布的一系列关于Windows..net和C#的公告,.Net开发者将在2019年,迎来自己的高光时刻,毕竟“世界上只有少数几种语言是多功能的,而没有一个像C#那样干净整洁.” 一.现在学C# ...
- 6、Java运算符
运算符的分类 算数运算符 二元运算符 算术运算符中 = - * / % 属于二元运算符,二元运算符指的是需要两个操作数才能完成的运算的运算术. 整数运算规则 1.如果两个操作数有一个为Long,则结果 ...