浙大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 ...
随机推荐
- typings 命令使用注意
1.如果要查询一些库 typings search xxx 2.安装jquery node 这样的库要这样 typings dt~node --global --save 一定要dt~xxx ,然 ...
- XML+AJAX
- 创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文件或程序集“System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一个依赖项。系统没找到指定的文件
创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文 ...
- 关于sbutils中的sblaunch插件的疑惑
一.sbutils介绍 sbutils是一个开源的越狱手机基础功能的插件包,其中包含sblaunch这个启动插件,该插件可以实现命令行下面打开app并传递一个url. sbutils下载地址:http ...
- 杭州蓝松科技推出的安卓端的USB转串口调试助手, 欢迎下载使用
杭州蓝松科技推出的安卓端的USB转串口调试助手, 欢迎下载使用 下载地址:http://files.cnblogs.com/guobaPlayer/%E8%93%9D%E6%9D%BEUSB%E4%B ...
- LeetCode 328. Odd Even Linked List C#
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...
- Homestead 使用总结
homestead Laravel Homestead是一个官方预封装的Vagrant"箱子" 内置 Nginx.PHP 5.6.MySQL.Postgres.Redis.Memc ...
- asp xml对象转换为string
'xml文件中没有属性的情况 Dim xmlStrxmlStr="<root><count>1</count><error>0</err ...
- C语言学习 数独游戏
摘要:花了1周多时间学习了C语言,开始练手写解数独游戏的程序. C语言学习 数独游戏 作者:乌龙哈里 时间:2015-11-22 平台:Window7 64bit,TCC 0.9.26(x86-64 ...
- OpenCV FileStorage 使用记录
FileStorage OpenCV 中的 FileStorage 类能够读写硬盘中的.xml和.yaml文件,这里我们只讨论对 .xml 的以下几种操作: 写入(FileStorage::WRITE ...