1059. Prime Factors (25)

时间限制
50 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
HE, Qinming

Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1 * p2^k2 *…*pm^km.

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"iostream"
#include "algorithm"
#include "math.h"
#include<stdlib.h>
using namespace std;
long int n;
bool IsPrimer(long n)
{
long i,tmp;
tmp = sqrt(double(n))+1;
for(int i=3;i<=tmp;i++)
if(n%i==0)
return false;
return true;
}
int main()
{

cin >> n;
cout<<n<<"=";
if(n==1)
cout<<n<<endl;
else
{
int k;
int tmp = n;
for(int i=2;i<=tmp;i++)
{
k=0;
if(IsPrimer(i))
{
while(n%i==0)
{
k++;
n=n/i;
}
}
if(k>1)
{
cout<<i<<"^"<<k;
}
else if(k==1)
cout<<i;
if(n!=1&&k>=1)
cout<<"*";
else if(n==1)
break;
}
}
cout<<endl;
return 0;
}


浙大pat 1059 题解的更多相关文章

  1. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  2. 浙大pat 1025题解

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  3. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  4. 浙大PAT 7-06 题解

    #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...

  5. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  6. 浙大 pat 1003 题解

    1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  7. 浙大 pat 1038 题解

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  8. 浙大 pat 1047题解

    1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  9. 浙大pat 1054 题解

    1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...

随机推荐

  1. 对于笔试题--“good and abc”的理解

    今天朋友问了一个面试题,题目如下: public class Example{ String str=new String("good"); char[]ch={'a','b',' ...

  2. yeoman生成react基本架构

    工欲善其事必先利其器.在开始react开始之前,我们先使用一系列的前段工具构建自己的前端集成解决方案. 环境配置: Bower,node js,npm,Grunt,Gulp,Yeoman 作者一直使用 ...

  3. 【锋利的Jquery】读书笔记五

    jquery表单 表格操作 表单从基本的得到和失去焦点表单验证 <script type="text/javascript"> $(function(){ $(&quo ...

  4. Java 基础知识(一)

    Java基础知识篇: 一.关键字解释 1. final:修饰非抽象类,非抽象方法和属性, 以及修饰方法参数,代表“无法改变的”.出于对设计或者效率的考虑使用该关键字. final类无法被继承,fina ...

  5. maven项目如何引用本地的jar包

    下载该jar包到本地(如下载目录结构为:D:\Users\lu.wang\Downloads\searchservice\searchservice\jar\ttd.search.searchserv ...

  6. svn客户端的安装与中文版本语言库

    首先在mac下下载svn或者其他软件请看另一篇博客链接:http://www.cnblogs.com/minyc/p/myc201606191543.html 另附svn常用命令操作详解:http:/ ...

  7. Atom编辑器之加快React开发的插件汇总

    汇总下比较实用的atom插件[偏react开发的]-- 博主发现这个还是比较全面的! atom-react-autocomplete–项目内,组件名及状态的自动补全  autocomplete-js- ...

  8. 整理一些css在使用中的小技巧(进行中)

    1. 消除li排列display:inline-block的间隙 ul{ font-size:; } ul li{ display:inline-block; }

  9. Chapter 2 Open Book——32

    I paused for a long moment, and then made the mistake of meeting his gaze. 我停顿了很长时间,然后错误的去对视了他的凝视 我停 ...

  10. 6.MyBaits的分页和缓存查询

    1. 创建javaweb项目MyBaits_Page_CaChe 2.在项目的WebRoot下的WEB-INF下的lib文件下加入jar文件 log4j-1.2.17.jar mybatis-3.2. ...