蓝桥杯 算法提高 8-1因式分解
来源:互联网 发布:反转二叉树 js 编辑:程序博客网 时间:2024/06/05 16:22
问题描述
设计算法,用户输入合数,程序输出若个素数的乘积。例如,输入6,输出2*3。输入20,输出2*2*5。
样例
与上面的样例输入对应的输出。
例:
数据规模和约定
输入数据中每一个数在int表示范围内。
#include <iostream>#include <vector>#include <string>#include <queue>using namespace std;bool isPrime(int n) { if (n < 2) return false; for (int i = 2; i*i <=n; i++) { if (n%i == 0) return false; } return true;}int main() { int n, a[10010] = { 0 }, cnt = 0; int p = 2; cin >> n; while (n > 1) { if (n%p == 0&&isPrime(p)) { a[cnt++] = p; n /= p; } else { p++; } } //cout << cnt; for (int i = 0; i < cnt; i++) { cout << a[i]; if (i != cnt - 1) cout << "*"; } cout << endl; cin >> n; return 0;}
阅读全文
0 0
- 蓝桥杯 算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解
- [蓝桥杯]算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 算法提高 8-1因式分解
- 蓝桥杯 ADV-223 算法提高 8-1因式分解
- 蓝桥杯 算法提高 8-1因式分解(Java解题)
- 算法提高——8-1因式分解
- 算法提高 ADV-223 8-1因式分解
- 蓝桥杯-8-1因式分解(java)
- 小学期实践
- Ciclop开源3D扫描仪软件---Horus源码分析之point_cloud_roi.py
- C/C++ --IO小程序附带运行过程 & get()函数解析
- 《机器学习实战》——2.k-近邻算法(KNN )函数总结
- JSP+MVC基础知识
- 蓝桥杯 算法提高 8-1因式分解
- Git详细使用教程
- 语音识别的前端处理
- leetcode 122.Best Time to Buy and Sell Stock II —— 贪心
- Comparable和Comparator 是什么以及区别
- UnityShader初级篇——渐变纹理
- touchpad hid report descrpt windows sample descript
- python_socket网络套接字
- 1079. 延迟的回文数 (20)