浙大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 ...
随机推荐
- mongodb tip-1
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px "Helvetica Neue"; color: #454545 } p. ...
- 【USACO】接住苹果
接住苹果奶牛喜欢吃苹果.约翰有两棵苹果树,有 N 只苹果会从树上陆续落下.如果掉苹果的时候,贝西在那棵树下,她就能接住苹果.贝西一开始在第一棵树下.在苹果掉落之前,她有足够的时间来回走动,但她很懒,最 ...
- 单机Hadoop搭建
通过一段时间的学习,我在我的centos上安装了单机hadoop,如果这对你有帮助,就进来探讨学习一下 Hadoop伪分布式配置 Hadoop 可以在单节点上以伪分布式的方式运行,Hadoop 进程以 ...
- jQuery datepicker和jQuery validator 共用时bug
当我们给一个元素绑定一个datepick后又要对它用validator进行验证时会发现验证并没有成功 因为当点击该元素时候input弹出datepick的UI就已经失去了焦点它验证的仍然是前一个值, ...
- Openjudge-NOI题库-旅行-数论
题目描述 Description 转眼毕业了,曾经朝夕相处的同学们不得不都各奔东西,大家都去了不同的城市开始新的生活.在各自城市居住了一段时间后,他们都感到了一些厌倦,想去看看其他人的生活究竟如何,于 ...
- CODE[VS]-蛇形矩阵-模拟-天梯白银
题目描述 Description 小明玩一个数字游戏,取个n行n列数字矩阵(其中n为不超过100的奇数),数字的填补方法为:在矩阵中心从1开始以逆时针方向绕行,逐圈扩大,直到n行n列填满数字,请输出该 ...
- IOS开发调整UILabel的行间距
CGFloat heih = 20; NSString * cLabelString = @"这是测试UILabel行间距的text.这是测试UILabel行间距的text.n 这是测试 ...
- String使用拼接对性能的影响和原因。
需要频繁的拼接String的时候,使用\'+\'拼接会影响性能,应该用StringBuilder或者StringBuffer的append反方法来拼接,从执行速度上来讲:StringBuilder & ...
- python绝技 — 用Scapy测试无线网卡的嗅探功能
代码 #!/usr/bin/python #--*--coding=utf-8--*-- from scapy.all import * def pktPrint(pkt): if pkt.hasla ...
- Facebook FB.init() status参数的作用
意思是 status 设为 ture 之后调用 FB.getLoginStatus() 不再产生网络请求,数据已经在 FB.init() 调用的时候被请求回来,缓存住了.