【題解】ZeroJudge e566: 10190 – Divide, But Not Quite Conquer!

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e566
【解題想法】連除計算

  • ⚠️注意:兩個非負整數n和m,可能為 0。
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, m;
    while (cin >> n >> m){
        vector <int> ans;
        bool boring = false;
        if (n == 0 || m == 0) boring = true;
        else {
            ans.push_back(n);
            while (n > 1) {
                if (n%m == 0){
                    n /= m;
                    ans.push_back(n);
                } else {
                    boring = true;
                    break;
                }
            }
        }
        if (boring) cout << "Boring!\n";
        else {
            for (auto i: ans) cout << i << " ";
            cout << "\n";
        }
    }
    return 0;
}
分享本文 Share with friends