1059 Prime Factors(25 分)
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#include<cstdio>
#include<cmath>
const int maxn = ; bool is_prime(int n){
if(n == ) return false;
int sqr = (int)sqrt(1.0*n);
for(int i = ; i <= sqr; i++){
if(n % i == ) return false;
}
return true;
} int prime[maxn],pNum = ;
void Find_prime(){
for(int i = ; i < maxn; i++){
if(is_prime(i) == true){
prime[pNum++] = i;
}
}
} struct facot{
int x,cnt;
}fac[];
int main(){
Find_prime();
int n;
scanf("%d",&n);
int num = ;
if(n == ) printf("1=1");
else{
printf("%d=",n);
int sqr = (int)sqrt(1.0*n);
//printf("prime[0]");
for(int i = ; i < pNum ; i++){
//printf("%d",i);
if(n % prime[i] == ){
fac[num].x = prime[i];
fac[num].cnt = ; while(n % prime[i] == ){
fac[num].cnt++;
n /= prime[i];
}
num++;
}
if(n == ) break;
}
if(n != ){
fac[num].x = n;
fac[num].cnt = ;
}
//printf("1\n");
for(int i = ; i < num; i++){
if(i > ) printf("*");
printf("%d",fac[i].x);
if(fac[i].cnt > ) printf("^%d",fac[i].cnt);
}
}
return ;
}
1059 Prime Factors(25 分)的更多相关文章
- PAT 甲级 1059 Prime Factors (25 分)  ((新学)快速质因数分解,注意1=1)
		1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime ... 
- 1059 Prime Factors (25分)
		1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ... 
- 【PAT甲级】1059 Prime Factors (25 分)
		题意: 输入一个正整数N(范围为long int),输出它等于哪些质数的乘积. trick: 如果N为1,直接输出1即可,数据点3存在这样的数据. 如果N本身是一个质数,直接输出它等于自己即可,数据点 ... 
- PAT 1059. Prime Factors (25)   质因子分解
		题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ... 
- 1059. Prime Factors (25)
		时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ... 
- PAT Advanced  1059  Prime Factors (25) [素数表的建⽴]
		题目 Given any positive integer N, you are supposed to find all of its prime factors, and write them i ... 
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
		用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ... 
- PAT (Advanced Level) 1059. Prime Factors (25)
		素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ... 
- pat1059. Prime Factors (25)
		1059. Prime Factors (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ... 
- PAT  1059 Prime Factors[难]
		1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime fa ... 
随机推荐
- 【SQL Server DBA】维护语句:删除并创建外键约束、获取建表语句
			原文:[SQL Server DBA]维护语句:删除并创建外键约束.获取建表语句 1.删除外键约束,建立外键约束 先建立3个表: /* drop table tb drop table tb_b dr ... 
- Centos7阿里云安装OpenProject-亲测
			10/182019年10月18日13:50 参考 <https://ywnz.com/linuxyffq/4085.html> 说在前头:网上有各种教程,包括官方自己的教程,在阿里云服务器 ... 
- Linux 常见压缩格式详解
			linux 文件压缩格式详解 压缩文件原理 在计算机科学和信息论中,数据压缩或者源编码是按照特定的编码机制用比未经编码少的数据比特(或者其它信息相关的单位)表示信息的过程.例如,如果我们将" ... 
- node中用的cookie-parser插件设置的max-age,和普通正常设置max-age的计算方式不一样
			在cookie-parser中通过max-age设置的cookie的过期时间是按照毫秒计算的; 在普通设置的时候max-age后面的值是按秒计算的; 
- impala 表迁移方式 partquet数据文件移动方法
			1.原表查询:select count(*) from edm.ucard_wxd0123 where stat_dt = '2024-01-09' and id_no = '110101199003 ... 
- linux uniq命令用法
			uniq命令: 对指定的ASCII文件或标准输入进行唯一性检查,以判断文本文件中重复出现的行,常用于分析日志:查看tcp各个状态连接数,ip或域名连接数排名等等场景,一般与 sort 命令结合使用. ... 
- 采集代理ip 地址【西刺,快代理】
			# 嗯,...因为经常需要使用代理去抓一点东西,就有了下面一段代码,第一版不是很好,后面用到了再来优化 import re,pymysql,time,redis from urllib.request ... 
- Oracle 定时JOB
			讲一下Oracle创建临时job小窍门,创建Oracle临时JOB是为了临时执行调用过程或者函数,只调用一次. 1.创建Oracle临时job declare VJOB number; begin ... 
- WinServer-SMTP服务
			摘要 SMTP服务是用来发送邮件的,常用于代码中发送邮件,不能接收.本章介绍SMTP服务的安装,配置. 搭建F5负载均衡集群注意事项: 1.集群不能与exchang在同网段,否则发不出邮件. 2.AP ... 
- layui 添加
			{include file="Public:inner_header" /} <link rel="stylesheet" href="__ST ... 
