Source:

PAT A1059 Prime Factors (25 分)

Description:

Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p​1​​​k​1​​​​×p​2​​​k​2​​​​×⋯×p​m​​​k​m​​​​.

Input Specification:

Each input file contains one test case which gives a positive integer N in the range of long int.

Output Specification:

Factor N in the format N = p​1​​^k​1​​*p​2​​^k​2​​**p​m​​^k​m​​, where p​i​​'s are prime factors of N in increasing order, and the exponent k​i​​ is the number of p​i​​ -- hence when there is only one p​i​​, k​i​​ is 1 and must NOT be printed out.

Sample Input:

97532468

Sample Output:

97532468=2^2*11*17*101*1291

Keys:

  • 模拟题

Attention:

  • 注意N==1的情况

Code:

 /*
Data: 2019-07-08 20:14:37
Problem: PAT_A1059#Prime Factors
AC: 14:40 题目大意:
打印正整数N的质因子,及其个数
*/
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
struct node
{
LL p,k;
}; int main()
{
LL n;
vector<node> fac;
scanf("%lld", &n);
printf("%lld=", n);
for(LL i=; i<=(LL)sqrt(1.0*n); i++)
{
if(n%i == )
{
node t = node{i,};
while(n%i== && n!=)
{
t.k++;
n /= i;
}
fac.push_back(t);
}
if(n == )
break;
}
if(n != )
fac.push_back(node{n,});
if(fac.size()==)
printf("");
for(int i=; i<fac.size(); i++)
{
printf("%lld", fac[i].p);
if(fac[i].k != )
printf("^%lld", fac[i].k);
printf("%c", i==fac.size()-?'\n':'*');
} return ;
}

PAT_A1059#Prime Factors的更多相关文章

  1. [CareerCup] 7.7 The Number with Only Prime Factors 只有质数因子的数字

    7.7 Design an algorithm to find the kth number such that the only prime factors are 3,5, and 7. 这道题跟 ...

  2. 1059. Prime Factors (25)

    时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...

  3. PAT 1059. Prime Factors (25) 质因子分解

    题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...

  4. 2014辽宁ACM省赛 Prime Factors

    问题 L: Prime Factors 时间限制: 1 Sec  内存限制: 128 MB [提交][状态][论坛] 题目描写叙述 I'll give you a number , please te ...

  5. PAT1059:Prime Factors

    1059. Prime Factors (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...

  6. A1059. Prime Factors

    Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...

  7. PAT 甲级 1059 Prime Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488 Given any positive int ...

  8. PAT 1059 Prime Factors[难]

    1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ...

  9. pat1059. Prime Factors (25)

    1059. Prime Factors (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...

随机推荐

  1. FATFS模块应用笔记

    FATFS模块应用笔记 如何港 范围 内存使用 模块尺寸缩小 长文件名 统一的API 重入 复制文件访问 性能有效文件访问 对闪存介质考虑 关键的第 延长使用FATFS API 关于FATFS许可证 ...

  2. python模块学习之HTMLTestRunner模块生成HTML测试报告

    #!/usr/bin/env python #-*- coding:utf-8 -*- from HTMLTestRunner import HTMLTestRunner import time im ...

  3. 这里ajax需要改成同步

    var flag = true; var title = $("#modal").find("input[name=groupname]").val(); /* ...

  4. JSP 虚拟路径设置

    编辑server.xml 在Host标签内加  :path为虚拟路径  docBase为绝对路径 <Context path="/icon"  docBase="C ...

  5. MyEclipse增强代码补全

    MyElipse的默认代码提示功能隐藏了许多细节,需要开发者手动设置,一起来设置吧,让你的myeclpse更强大. 方法 1 打开MyEclipse 6.0.1,然后“window”→“Prefere ...

  6. js的内部特性--属性

    使用方法:通过调用Object.defineProperty(对象,"对象属性",{}进行的操作}) 当对一个对象的属性的属性类型中vlue设置为一个值时,则这个对象的这个属性的值 ...

  7. spark性能调优02-JVM调优

    1.降低cache操作的内存占比 1.1 为什么要降低cache操作的内存占比 spark的堆内存分别两部分,一部分用来给Rdd的缓存进行使用,另一部分供spark算子函数运行使用,存放函数中的对象 ...

  8. Windows Nginx 教程

    1. 下载Nginx: Nginx下载 (官方网站) 作者使用版本  Stable version  nginx/Windows-1.12.0

  9. MySQL锁机制浅析

    MySQL使用了3种锁机制 行级锁,开销大,加锁慢,会出现死锁,发生锁冲突的概率最高,并发度也最高 表级锁,开销小,加锁快,不会出现死锁,发生锁冲突的概率最低,并发度最低 页级锁,开销和加锁时间界于表 ...

  10. iOS音频Error

    最近在cocos应用上发现一个比较奇怪的bug,当应用正在调用录音的时候,按下home键回到后台,然后打开一个音乐播放器播放一个音乐,再回到游戏中游戏就会卡死. 之前录音和播放设置是下方: 播放: [ ...