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
#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 分)的更多相关文章

  1. 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 ...

  2. 1059 Prime Factors (25分)

    1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ...

  3. 【PAT甲级】1059 Prime Factors (25 分)

    题意: 输入一个正整数N(范围为long int),输出它等于哪些质数的乘积. trick: 如果N为1,直接输出1即可,数据点3存在这样的数据. 如果N本身是一个质数,直接输出它等于自己即可,数据点 ...

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

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

  5. 1059. Prime Factors (25)

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

  6. 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 ...

  7. PAT甲题题解-1059. Prime Factors (25)-素数筛选法

    用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...

  8. PAT (Advanced Level) 1059. Prime Factors (25)

    素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

  9. pat1059. Prime Factors (25)

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

  10. PAT 1059 Prime Factors[难]

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

随机推荐

  1. MyBatis Generator 自动生成的POJO对象的使用(二)

    四.Example Class使用说明 示例类指定如何构建动态where子句. 表中的每个非BLOB列都可以选择包含在where子句中. 示例是演示此类用法的最佳方法. 示例类可用于生成几乎无限制的w ...

  2. Python 使用gevent下载图片案例

    import urllib.request import gevent from gevent import monkey monkey.patch_all() def downloader(img_ ...

  3. 4.JUC之AQS框架

    一.简介 1.AQS AQS是AbstractQueuedSynchronizer的简写,直白的翻译:抽象队列同步器,jdk1.5后出现 Provides a framework for implem ...

  4. 一个让Java事半功倍的反射库

    在Java和Android中,我们常常会使用反射来达到一些兼容的目的.Java原生提供的反射很是麻烦,使用起来很是不方便.比如我们想要调UserManager的静态方法get,使用原生的实现如下 tr ...

  5. JavaIO模型--装饰者模式

    JavaIO体现出装饰者的设计模式 今天在学SparkRDD之前,听了一堂复习JavaIO的课,觉得讲得不错 Java的IO一直让我觉得一层一层的很麻烦,刚接触的时候,理不太清楚 只知道要分解为输入输 ...

  6. Nuget & VS Plugin

    VS Plugin vsCode:https://marketplace.visualstudio.com/vscode vs:https://marketplace.visualstudio.com ...

  7. Python标准库3.4.3-random

    9.6. random — Generate pseudo-random numbers Source code: Lib/random.py  翻译:Z.F. This module impleme ...

  8. IIS 自动化发布工具实现【一】

    [持续更新中啦] 过去一年,有在尝试做.net 这块的开发运维工作.基于现在的开发场景,写了一套差异发布工具.后面用python重写了一套,现学现卖. 主要功能: 差异打包.自动发布.自动回滚 实现架 ...

  9. 改进Bert----spanBERT

    SpanBert:对 Bert 预训练的一次深度探索 SpanBERT: Improving Pre-training by Representing and Predicting Spans 解读S ...

  10. Gym - 102346D Denouncing Mafia 取k叶子节点使叶子到根覆盖节点数最大

    给你一棵树 你可以取K条链 一条链为根到叶子的路径 问你K条链最多覆盖树上多少个节点 贪心的做 肯定是每次取最长链 但是取完最长链 一颗树就会变为若干个森林 我们要维护当前所有森林里的最长链 ans数 ...