1059. Prime Factors (25)
来源:互联网 发布:杨幂睡小鲜肉知乎 编辑:程序博客网 时间:2024/05/18 01:07
1059. Prime Factors (25)
时间限制
50 ms
内存限制
65536 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:97532468Sample Output:
97532468=2^2*11*17*101*1291
题意:将一个整数分解为若干素数的乘积,注意N==1的情况即可。
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <vector>using namespace std;typedef long long int ll;vector< pair<ll,int> > my_vector;int main(){ll num;cin >> num;cout << num << "=";if(num==1){cout << 1 << endl;return 0;}ll tmp = sqrt(num)+1;int count;for(ll i=2; i<=tmp; i++){if(num%i==0){count = 0;do{count++;num /= i;}while(num%i==0);my_vector.push_back({i,count});}}if(num!=1)my_vector.push_back({num,1});int size = my_vector.size();for(int i=0; i<size; i++){cout << my_vector[i].first;if(my_vector[i].second>1) cout << "^" << my_vector[i].second; if(i+1!=size) cout << "*";} cout <<endl;return 0;}
0 0
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 机器学习资料
- BCB 中 Application->CreateForm 和 New 的一个区别
- POJ 1475 Pushing Boxes 嵌套BFS -
- Qt学习之五: 添加动作与资源文件
- 大数据IMF传奇行动绝密课程第54课:Spark性能优化第十季之Spark统一内存管理
- 1059. Prime Factors (25)
- Java数组运算
- Android简易实战教程--第二十七话《自定义View入门案例之开关按钮详细分析》
- Java Socket和ServerSocket
- JAVA语法基础Demo练习
- 大数据IMF传奇行动绝密课程第55课:60分钟从零起步驾驭Hive实战
- 微信公众平台--接收普通消息与事件
- 学习ucos ii 的一点一滴----ucos ii中的的任务(一)
- 加载场景,背景,按钮,音乐,切换场景,初始plist