#include <iostream>
using namespace std;
#include <cmath>
const int maxn = 1000010;
struct factor{
int m = 0,cnt = 0;
};
factor p[maxn];
int main()
{
int k = 2;//第一个素数int x; int e = 1;//用于计算累积乘的结果,来控制*号的输出cin >> x;int t = x;//找质因子的过程会把改变x,这里备份一个用于输出格式if(x == 1){
//如果为输入为1直接结束程序cout << x << "=" << 1;return 0; }while(x > 1){
//质因数if (x % k == 0){
x = x / k;p[k].m = k;p[k].cnt++; }else k++;}cout << t << "=";//以下为控制输出格式for(int i = 0; i < maxn; i++){
if(p[i].cnt != 0){
e =pow(p[i].m, p[i].cnt) * e;if(e < t){
if(p[i].cnt > 1) cout << p[i].m << "^" << p[i].cnt << "*";else if(p[i].cnt == 1) cout << p[i].m << "*";}else {
if(p[i].cnt > 1) cout << p[i].m << "^" << p[i].cnt;else if(p[i].cnt == 1) cout << p[i].m;}}}return 0;
}
详细解决方案
PAT A1059 Prime Factors 质因数
热度:89 发布时间:2023-11-25 15:56:21.0
相关解决方案
- Prime Palindromes有错
- 怎样设计boolean prime(int n)方法,可用来判别n是否为质数,还有错误处理
- USCAO-Section 1.3 Prime Cryptarithm
- POJ 2689 Prime Distance 素数筛选 -
- PAT甲级-1059 Prime Factors (25分)
- Prime Path - POJ 3126
- HDOJ 2138 How many prime numbers
- HDOJ 2136 Largest prime factor
- HDOJ 1016 Prime Ring Problem(DFS深度优先搜索)
- POJ - 3126 Prime Path (素数表+BFS)
- ACM_搜索:杭电oj1016:Prime Ring Problem
- [PTA]1059 Prime Factors(分解质因数)
- HDOJ1016 Prime Ring Problem (DFS,回溯,,打表)
- 求质数(Prime Number 素数)的方法——厄拉多塞筛法
- Consecutive Factors (20) 数论
- HDU 2136 Largest prime factor (水)
- Gym 101981J Prime Game (组合计数)
- 【回炉重造】POJ-3126.Prime Path 题解
- POJ - 3126 - Prime Path 【BFS + 素数打表】
- 【CodeForces】【中途相遇法】【二分答案】912E Prime Gift
- (复习次数:1)Prime Path POJ3126
- 思维漏洞:P1211 [USACO1.3]牛式 Prime Cryptarithm
- hdu-1016 Prime Ring Problem(dfs)
- 2018年ACM-ICPC 南京现场赛 J.Prime Game
- POJ - 2689 Prime Distance(线性筛法)
- PAT A1059 Prime Factors 质因数
- 欧拉计划007--10001st prime
- 欧拉计划003--Largest prime factor
- PAT甲级1059 Prime Factors
- 洛谷 P4752 Divided Prime