-
Notifications
You must be signed in to change notification settings - Fork 0
/
10190 - Divide, But Not Quite Conquer!
64 lines (58 loc) · 1.27 KB
/
10190 - Divide, But Not Quite Conquer!
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
63
64
#include <iostream>
#include <set>
#include<vector>
#include<string>
#include<sstream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int n, m;
while (cin >> n >> m) {
if (n <= 1 || m <= 1) {
cout << "Boring!" << endl;
continue;
}
vector<int> nums;
for (int i = n ; i == 1 || (i > 1 && i % m == 0); i /= m) {
nums.push_back(i);
}
int numsSize = nums.size();
if (numsSize == 0 || nums[numsSize - 1] != 1) {
cout << "Boring!" << endl;
continue;
}
for (auto i = nums.begin(); i != nums.end(); i++) {
cout << *i << " ";
}
cout << endl;
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
while(cin>>n>>m){
bool flag=true;
vector<int> vec;
vec.push_back(n);
int number=0;
while(n%m==0){
n = n/m;
vec.push_back(n);
if(n==1){
break;
}
}
if(n!=1){
cout<<"Boring!"<<endl;
continue;
}
for(int i=0;i<vec.size();i++){
cout<<vec[i]<<" ";
}
cout<<endl;
}
}