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 ...
随机推荐
- 爬取猎聘大数据岗位相关信息--Python
猎聘网站搜索大数据关键字,只能显示100页,爬取这一百页的相关信息,以便做分析. __author__ = 'Fred Zhao' import requests from bs4 import Be ...
- 通过angular.js实现MVC的基本步骤
通过ng实现MVC的基本步骤: ①创建模块 var app = angular.module('模块名字',['依赖模块1','依赖模块2']) ②调用模块 ngApp--> ng-app=&q ...
- 使用 U 盘装个 winXP 原版镜像玩红警
winXP 自身是不支持 U 盘启动的,所以用 poweriso 直接制作的 U 盘是没用的 可以使用 wintoflash 操作,下载地址: https://wintoflash.en.softon ...
- nginx支持http2协议
1.http2协议 HTTP 2.0 的主要目标是改进传输性能,实现低延迟和高吞吐量.从另一方面看,HTTP 的高层协议语义并不会因为这次版本升级而受影响.所有HTTP 首部.值,以及它们的使用场景都 ...
- 20140922 tcpip3次握手 分段 分页 spooling 位示图
tcpip3次握手 http://www.cnblogs.com/CBDoctor/archive/2012/10/17/2727073.html 操作系统:http://blog.csdn.ne ...
- JPA 唯一索引
@Table(name = "adam_module", uniqueConstraints = @UniqueConstraint(columnNames = {"in ...
- 一份详尽的 Java 问题排查工具清单,值得收藏!
| grep 5 -A 3 #上匹配seq 10 | grep 5 -B 3 #下匹配seq 10 | grep 5 -C 3 #上下匹配,平时用这个就妥了cat f.txt | g ...
- Python面试题之下面代码会输出什么
def f(x,l=[]): for i in range(x): l.append(i*i) print l f(2) f(3,[3,2,1]) f(3) 答案: [0, 1] [3, 2, 1, ...
- lzma 知识点滴
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/xuweiwei1860/article/details/31419195 LZMA(Lempel-Z ...
- chroot 试用alpinelinux安装软件包的问题
前边有说明使用chroot 体验alpinelinux,但是因为默认没有dns server,造成软件包无法下载 现象 问题原因 解决方法 copy host resolv.conf 到alpine ...