当前位置:网站首页>将一个正整数分解质因数,要求分解成尽可能小的多个的因数。
将一个正整数分解质因数,要求分解成尽可能小的多个的因数。
2022-07-26 06:16:00 【枯木何日可逢春】
题目:
将一个正整数分解质因数,要求分解成尽可能小的多个的因数。
例如:输入90,打印出90=233*5。
代码:
#include<iostream>
#include<vector>
using namespace std;
void f(int num, vector<int> &vec) {
for (int i = 2; i <= num; ++i) {
if (num % i == 0) {
vec.push_back(i);
f(num / i, vec);
return;
}
}
}
int main() {
int num;
cin >> num;
vector<int> vec;
f(num, vec);
cout << num << "=";
if (vec.size() > 0) {
cout << vec[0];
}
for (int i = 1; i < vec.size(); ++i) {
cout << '*' << vec[i];
}
return 0;
}
运行结果:

边栏推荐
- 【Oracle SQL】计算同比与环比(列转行进行偏移)
- Interpretation of TPS motion (cvpr2022) video generation paper
- 【Day_03 0420】字符串中找出连续最长的数字串
- 实习运维知识积累
- 【Day_04 0421】计算糖果
- Understanding the mathematical essence of machine learning
- Do it yourself smart home: intelligent air conditioning control
- BPG笔记(四)
- [2023 Jerry technology approval test questions in advance] ~ questions and reference answers
- 【无标题】
猜你喜欢

Code runner for vs code, with more than 40million downloads! Support more than 50 languages

Leetcode:934. The shortest Bridge

How to divide the disks under the devices and drives in win10 new computer

Age is a hard threshold! 42 years old, Tencent level 13, master of 985, looking for a job for three months, no company actually accepted!

Mysql45 talking about infrastructure: how is an SQL query executed?

A tool for quickly switching local host files -- switchhosts

How can machinery manufacturing enterprises do well in production management with the help of ERP system?

Cdga | how to build data asset catalogue?

逆序打印链表

Workflow activiti5.13 learning notes (I)
随机推荐
Map集合继承结构
[SQL optimization] (big table tips) sometimes a 2-hour SQL operation may take only 1 minute
Niuke network: TOPK problem of additive sum between two ordinal groups
If introduced according to the open source framework
Interpretation of TPS motion (cvpr2022) video generation paper
【Day05_0422】C语言选择题
Docking wechat payment (II) unified order API
Byte interview question - judge whether a tree is a balanced binary tree
分布式 | 实战:将业务从 MyCAT 平滑迁移到 dble
二叉树的前中后序遍历——本质(每个节点都是“根”节点)
Ganglia安装部署流程
[free and easy to use] holiday query interface
[day_060423] no two
Leetcode:940. How many subsequences have different literal values
Xiao He shows his sharp corners and says hello to flutter app
Introduction to three feasible schemes of grammatical generalization
[day05_0422] C language multiple choice questions
Redis sentinel cluster setup
Taobao JD pinduoduo Tiktok taote 1688 and other multi platform commodity app details API interfaces (commodity details page data interface, commodity sales interface, keyword search commodity sales in
字节面试题——判断一棵树是否为平衡二叉树