1059 Prime Factors (25 分)【难度: 一般 / 知识点: 分解质因子 】
注意: 判断1000000007这种只有一个质数特别大的情况
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
bool check(int x)
{for(int i=2;i<=x/i;i++) if(x%i==0) return false;return true;
}
int main(void)
{int n; cin>>n;cout<<n<<"=";if(check(n)) {cout<<n;return 0;}for(int i=2;i<=n;i++) while(n%i==0) n/=i,mp[i]++;string ans;for(auto i=mp.begin();i!=mp.end();i++){if(i->second>1) ans+=to_string(i->first)+"^"+to_string(i->second)+"*";else ans+=to_string(i->first)+"*";}cout<<ans.substr(0,ans.size()-1);return 0;
}
1059 Prime Factors (25 分)【难度: 一般 / 知识点: 分解质因子 】相关推荐
- 【题目分析】1059 Prime Factors (25 分)
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given any positive integer N, you are supposed to find all of its ...
- 1059. Prime Factors (25)
题目如下: Given any positive integer N, you are supposed to find all of its prime factors, and write the ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
- 1059. Prime Factors (25)--taste
点击打开链接 注意: 1.对于输入为1的情况要特判 2.factor在int范围内开到10就足够 3.sqrt是范围,由于n后面被修改故范围要单写,且sqrt是double int sqr=sqrt( ...
- 1059 Prime Factors(25 分)(cj)
1059 Prime Factors(25 分) Given any positive integer N, you are supposed to find all of its prime fac ...
- 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[难]
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ...
- PAT甲级1059 Prime Factors :[C++题解]分解质因子
文章目录 题目分析 题目链接 题目分析 暴力求质因数 下面i就是质因子,s是质因子i的阶数. 暴力的时间复杂度O(n),会超时 void divide(int n){for(int i=2;i< ...
- 1059 Prime Factors(25 分)
Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...
最新文章
- windows 下xampp集成环境安装mongodb扩展
- Hyper-V 2016 系列教程25 配置NFS 存储服务器
- Openssl:构建CA的过程并实现web服务基于https访问的网络架构
- easyui messager 消息框 对话框
- 聚类算法:Hierarchical Clustering层次聚类
- ufs2.0测试软件,【玩机组教程】让你的一加3/3T的ufs2.0闪存速度焕发新生
- Android Studio的快捷键图文并茂
- 9-5:C++多态之多态和继承的经典题目以及面试中常考内容
- IPC--进程间通信三(共享内存)
- 突发!百度AI开发者大会李彦宏遭泼水 百度官方回应...
- Firefox和Chrome浏览器导出书签
- java 当前时间 15分钟_怎么用java 获取15分钟以前的时间
- 惊!使用nw.js将vue项目打包为可在xp系统运行的桌面程序
- 网站地图是什么,怎么制作和查看网站的地图呢?
- 公司邮箱登录入口哪个方便,邮箱移动办公哪个最好用?
- 冲水步骤(智能马桶开发记录)
- python应用开发实战第一章 兽人之袭0.0.1
- Qt QPlainTextEdit和QTextEdit区别
- mysql统计枚举值
- pygame实现动态小鸟飞行 + 打包发布