浙大pat 1059 题解
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 = 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 题解的更多相关文章
- 浙大pat 1035题解
1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...
- 浙大pat 1025题解
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 浙大pat 1011题解
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
- 浙大PAT 7-06 题解
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 浙大 pat 1003 题解
1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 浙大 pat 1038 题解
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- 浙大 pat 1047题解
1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- 浙大pat 1054 题解
1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...
随机推荐
- android 蓝牙连接与通讯(Bluetooth)
最近做了一个小项目,关于蓝牙的一个智能硬件.其中涉及到了蓝牙模块的操作.特记下蓝牙模块的操作过程.只记录下关于蓝牙部分的操作,具体业务逻辑不涉及其中.重点是记录下蓝牙的扫描.链接.通讯. 在使用蓝牙模 ...
- react-gulp-browserify
环境搭配参照 http://www.cnblogs.com/guolaomao/p/6276877.html 前半部分的内容. 首先安装browserify npm install --save-de ...
- 第12章 MySQL高级管理
1.手动更新权限后,需向服务器指出已对权限进行修改: (在MySQL提示符下)flush privileges; 2.查看用户所拥有的权限: 如: show grants for bookorama; ...
- SpringMVC @ResponseStatus 的用法
@ResponseStatus 用于修饰一个类或者一个方法,修饰一个类的时候,一般修饰的是一个异常类,如下, 声明一个异常类在类上面加上ResponseStatus注解,就表明,在系统运行期间,抛出A ...
- JS函数调用
function SayHello(word) { console.log(word); } function execute(Somefunction,value) { Somefunc ...
- centos 编译安装nginx
这里选用的是nginx-1.10.1稳定版,其基础依赖库有gcc.gcc-c++.pcre.zlib和openssl. pcre.zlib和openssl这三个依赖库在安装nginx时无需编译安装,下 ...
- GIT 代码管理工具 SourceTree
什么是git? git是一款开源的分布式版本控制工具 在世界上所有的分布式版本控制工具中,git是最快.最简单.最流行的 git的起源 作者是Linux之父:Linus Benedict Torval ...
- IIS 发布程序,无法输出EXCEL 问题处理
[解决方案1] 1:在服务器上安装office的Excel软件. 2:在"开始"->"运行"中输入dcomcnfg.exe启动"组件服务&quo ...
- 通过linux的iso镜像安装(RPM)扩展工具包
通过linux的iso镜像安装(RPM)扩展工具包 在linux安装软件时,现在越来越流行通过rpm指令安装完成,原因是:采用RPM安装简单方便:越来越多的软件提供RPM安装包:linux的IOS镜像 ...
- php强制下载文件并显示原始文件名
原来一直没有接触过,这几天一直在玩儿文件上传下载的东西.今天又遇到一个坑. 描述:文件上传至服务器后,如果是rar或则其他的非浏览器直接识别的格式,用户点击链接了后是可以直接就被下载下来的.那么如果上 ...