1059. Prime Factors (25)
来源:互联网 发布:佳能mg6280清零软件 编辑:程序博客网 时间:2024/05/23 02:08
特殊处理2,然后一次对x/3,/5。。。判断,知道x变成0
#include<iostream>#include<cmath>using namespace std;int main(){ long int x; cin >> x; cout << x << "="; if (x == 0 || x==1) {//额外处理0,1,的情况 cout << x << endl;exit(0); } int count = 0;int flag = 0; while (x % 2 == 0) { //先把2处理掉 count++; x = x / 2; flag = 1; } if (count >1) cout << "2^" << count; else if (count == 1) cout << "2"; for (int i = 3;x!=1;i += 2)//按3.5.7...顺序循环,知道x变成1 { count = 0; while (x%i == 0) { count++; x /= i; } if (flag == 1) { if (count > 1) printf("*%d^%d", i, count); else if (count == 1)printf("*%d", i); } else { if (count > 1) printf("%d^%d", i, count); else if (count == 1)printf("%d", i); flag = 1; } } cout << endl;}
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)
- CentOS安装Nginx
- 配置javaweb环境报如下错误
- Poj 3041 Asteroids 【最小点覆盖 匈牙利算法 】
- lintcode-入门-删除链表中的元素
- spring aop 日志
- 1059. Prime Factors (25)
- 微信小程序的全栈之路
- 欢迎使用CSDN-markdown编辑器
- linux常用命令(2)
- leecode 解题总结:123. Best Time to Buy and Sell Stock III
- CentOS 配置静态IP
- AJAX实现商品快速上下架,无刷新
- HTTP请求方法对照表
- 前端性能优化——个人搜集总结