---
# System prepended metadata

title: 'Divide, But Not Quite Conquer!(UVA10190)'
tags: [CPE一顆星必考題]

---

# Divide, But Not Quite Conquer!(UVA10190)
## 題目
[點我](https://onlinejudge.org/external/101/10190.pdf)

## 解題網站
[UVA](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1131)
[ZJ](https://zerojudge.tw/ShowProblem?problemid=e566)

## 演算法
```
1. 輸入a, b，若無法，則停止
2. 若(a == 0 or b == 0 or a == 1 or b == 1)，輸出Boring!
3. 宣告陣列v，設flag = 1
4. 不斷地將a除以b，並且將a放到v的末端，直到a = 1，若無法整除，則將flag設為0，並停止
5. 若flag，則輸出v，否則輸出Boring!
```
## 程式碼

```cpp=
#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b;
    while (cin >> a >> b) {
        if (a == 0 or b == 0 or a == 1 or b == 1) {
            cout << "Boring!" << endl;
            continue;
        }
        vector <int> v;
        int flag = 1;
        while (a != 1) {
            if (a % b != 0) {
                flag = 0;
                break;
            }
            v.push_back(a);
            a /= b;
        }
        v.push_back(1);
        if (flag) {
            cout << v[0];
            for (int i = 1; i < v.size(); i++) {
                cout << " " << v[i];
            }
            cout << endl;
        } else {
            cout << "Boring!" << endl;
        }
    }
    return 0;
}


```


:::warning
我覺得1 1應該要輸出1，但不知為何，要輸出Boring!才對
:::