PAT_A1059#Prime Factors
Source:
Description:
Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1k1×p2k2×⋯×pmkm.
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
=
p1^
k1*
p2^
k2*
…*
pm^
km, where pi's are prime factors of N in increasing order, and the exponent ki is the number of pi -- hence when there is only one pi, ki 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的更多相关文章
- [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. 这道题跟 ...
- 1059. Prime Factors (25)
时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...
- PAT 1059. Prime Factors (25) 质因子分解
题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...
- 2014辽宁ACM省赛 Prime Factors
问题 L: Prime Factors 时间限制: 1 Sec 内存限制: 128 MB [提交][状态][论坛] 题目描写叙述 I'll give you a number , please te ...
- PAT1059:Prime Factors
1059. Prime Factors (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...
- A1059. Prime Factors
Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...
- PAT 甲级 1059 Prime Factors
https://pintia.cn/problem-sets/994805342720868352/problems/994805415005503488 Given any positive int ...
- PAT 1059 Prime Factors[难]
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ...
- pat1059. Prime Factors (25)
1059. Prime Factors (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...
随机推荐
- 'pip' 不是内部或外部命令,也不是可运行的程序或批处理文件。
解决方法: 本方法适用于已经成功安装python并配置了环境变量. 1.到官网下载pip.py文件 https://pypi.python.org/pypi/pip#downloads 点击下载,解压 ...
- Tomcat负载均衡、调优核心应用进阶学习笔记(一):tomcat文件目录、页面、架构组件详解、tomcat运行方式、组件介绍、tomcat管理
文章目录 tomcat文件目录 bin conf lib logs temp webapps work 页面 架构组件详解 tomcat运行方式 组件介绍 tomcat管理 tomcat文件目录 ➜ ...
- 哈希表(hash)详解
哈希表结构讲解: 哈希表(Hash table,也叫散列表),是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度. ...
- java中接口的简单运用&java中的一些异常(运用myeclipse)
package test;//创建一个名为test的包 public class A4paper implements Paper { public String getSize(){ return& ...
- Linux NIO 系列(04-3) epoll
目录 一.why epoll 1.1 select 模型的缺点 1.2 epoll 模型优点 二.epoll API 2.1 epoll_create 2.2 epoll_ctl 2.3 epoll_ ...
- html-body标签中相关标签 02
今日主要内容: 列表标签 <ul>.<ol>.<dl> 表格标签 <table> 表单标签 <fom> 一.列表标签 列表标签分为三种. 1 ...
- spark复习总结01
1.MapReduce和spark的对比 MapReduce Spark 数据存储结构:磁盘hdfs文件系统的split 使用内存构建弹性分布式数据集RDD,对数据进行运算和cache 编程范式:Ma ...
- Javascript高级程序设计--读书笔记之面向对象(一)
哈哈哈万物皆对象,终于到了js的面向对象篇. 一.属性类型 (1)数据属性 数据属性包含一个数据值的位置,在这个位置可以写入和读取数值,数据属性有四个描述器行为的特性 [[Configurable]] ...
- Mysql中(@i:=@i+1)的作用
Oracle中有一个伪列rownum,可以在生成查询结果表的时候生成一组递增的序列号.MySQL中没有这个伪列,但是有时候要用,可以用如下方法模拟生成一列自增序号. (1)sql示例:select ( ...
- redis Sorted set 相关命令