浙大PAT1059 Prime Factors
来源:互联网 发布:返回顶部js代码 编辑:程序博客网 时间:2024/05/17 20:00
//常规题,没有什么多的技巧,关键不要漏掉1等特殊情况
#include<iostream>
#include<fstream>#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<string>
using namespace std;
//#define fin cin
int main()
{
/*ifstream fin("d:\in.txt" );
if (! fin.is_open())
{
cout << "Error opening file";
system("pause");
exit (1);
}*/
long N;
cin>>N;
cout<<N<<"=";
vector<int> data;
long temp=2;
if(N==1)
{
cout<<N;
return 0;
}
while(N!=1)
{
while(N%temp==0)
{
data.push_back(temp);
N=N/temp;
}
while(1)
{
temp++;
bool found=true;
for(int i=2;i<temp;i++)
{
if(temp%i==0)
{
found==false;
break;
}
}
if(found)
break;
}
}
int i=0;
int num=0;
int temp2=0;
int cishu=0;
while(i<data.size())
{
temp2=data[i];
num=1;
i++;
while(i<data.size()&&data[i]==temp2)
{
num++;
i++;
}
if(cishu==0)
{
if(num==1)
cout<<temp2;
else
cout<<temp2<<"^"<<num;
}
else
{
if(num==1)
cout<<"*"<<temp2;
else
cout<<"*"<<temp2<<"^"<<num;
}
cishu=1;
}
system("PAUSE");
return 0;
}
0 0
- 浙大PAT1059 Prime Factors
- pat1059 Prime Factors
- 浙大PAT 1059题 1059. Prime Factors
- Prime Factors
- Prime Factors
- Prime Factors
- Prime Factors
- PAT1059
- UVa 583-Prime Factors
- 1059. Prime Factors
- PAT_1059: Prime Factors
- UVa 583 - Prime Factors
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- PAT 1059. Prime Factors
- 1059. Prime Factors
- 1059. Prime Factors (25)
- 1059. Prime Factors
- mapreduce编程(一)-二次排序
- 一些开源的项目
- Android进程与线程
- LeetCode --- Add Digits解题分析
- SublimeText3 配置前端开发插件
- 浙大PAT1059 Prime Factors
- bzoj3991: [SDOI2015]寻宝游戏
- java字符串转16进制
- C++pair的用法
- C++Primer第5版读书笔记(第4章)
- [Python入门]Chapter10 列表
- ModelDriven背后的机制和Action,valueStack,Model,Context之间的关系图
- 手把手交大家在mac上用VMWare虚拟机装win7
- 面向对象——面向客户端编程