1570:基础练习 分解质因数

   题目:https://acmore.cc/problem/LOCAL/1570#desc

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 void decompose(int i)    //分解i的质因数
 6 {
 7     cout << i << "=";
 8     for (int j = 2; j <= i; ++j)
 9     {
10         if (i == j)
11         {
12             cout << j << endl;
13             break;
14         }
15         if (i%j == 0)
16         {
17             cout << j << "*";
18             i = i / j;
19             j--;    //注意此处j要回溯
20         }
21 
22     }
23 }
24 
25 
26 int main()
27 {
28     int a, b;
29     while (cin >> a >> b)
30     {
31         for (int i = a; i <= b; ++i)
32         {
33             decompose(i);
34         }
35     }
36 
37     return 0;
38     
39 }

猜你喜欢

转载自www.cnblogs.com/FengZeng666/p/10354893.html