Skip to content

Latest commit

 

History

History
108 lines (98 loc) · 1.27 KB

1019.md

File metadata and controls

108 lines (98 loc) · 1.27 KB

1019

1 Key Points

Sample Input 3:
2 2
Sample Output 3:
No
1 0

2 Answers

#include <cctype>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n, b;
vector<int> v1;
bool ans = true;

int findE(int n, int b) {
	ll i = 0, j = 1;
	while (j <= n) {
		i++;
		j *= b;
	}
	return i;
}

int main() {
	cin >> n >> b;
	int e = findE(n, b);
	// cout << e << endl;
	int p = pow(b, e - 1);
	for (int i = 0; i < e; ++i) {
		if (n >= p) {
			v1.push_back(n / p);
			n = n % p;
		}
		else {
			v1.push_back(0);
		}
		p /= b;
	}
	for (int i = 0; i < e / 2; ++i) {
		if (v1[i] != v1[e - 1 - i]) {
			ans = false;
		}
	}
	if (ans) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	if (e) {
		cout << v1[0];
		for (int i = 1; i < e; ++i) {
			cout << " " << v1[i];
		}
		cout << endl;
	}
	else {
		cout << n << endl;
	}
	return 0;
}

/*
Sample Input 1:
27 2
Sample Output 1:
Yes
1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No
4 4 1
Sample Input 3:
2 2
Sample Output 3:
No
1 0
*/

References