第三题一直为0,也不知道为啥,就很烦。
#include<iostream> #include<vector>
#include<stdio.h> #include<algorithm> #include<stdlib.h> using namespace std; bool nthUglyNumber(vector<int> test) { int a = test[0], b = test[1], c = test[2], d = test[3]; while (d > a) { if (d % c == 0) d = d / c; else { d = d - b; } } if (d == a) return true; else return false; } int main() { int T; cin >> T; vector<vector<int>> inputs(T, vector<int>(4)); for (int i = 0;i < T;i++) { cin >> inputs[i][0] >> inputs[i][1] >> inputs[i][2] >> inputs[i][3]; } bool a; for (int i = 0;i < T;i++) { a = nthUglyNumber(inputs[i]); cout << a; if (i < T - 1) cout << endl; } }