-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10190.cpp
62 lines (45 loc) · 1.07 KB
/
10190.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <cstdio>
using namespace std;
int main ()
{
int iN; //宣告被除數
int iM; //宣告除數
int iA[20]; //儲存A[i]的陣列
int i ; //計次迴圈
//輸入iN 和iM
while (cin >> iN >> iM)
{
//若iM小於1或是iN小於iM,則印出Boring ,再繼續輸入
if (iM <= 1 || iN < iM)
{
cout << "Boring!" << '\n';
continue;
}
//計次個數
int iCount = 1;
//計算下一個數,計算到iN的餘數為零且iN不小於iM
while (iN % iM == 0 && iN >= iM)
{
iA[iCount++] = iN;
iN /= iM;
}
//令iA[1]為iN
iA[iCount] = iN;
//若最後一個數不為零或計次為一時印出Boring
if ( iA[iCount] != 1 || iCount == 1)
{
cout << "Boring!" << '\n';
}
//否則印出數列
else
{
for ( i = 1 ; i < iCount ; i++)
{
cout << iA[i] << " ";
}
}
//印出最後一個數
cout << iA[i] << " " << '\n';
}
}