Time limit MS
Memory Limit 65536 KB
Code length limit 16000 B
Procedures for the award of questions StandardAuthor Chen, Yue
A number that would be the same when it was written forwards or backwards is known as a palindromic number. For example, 1234321 is a palindromic number. All digit numbers is palindromic numbers.
although palindromic numbers is most often considered in the decimal system, the concept of palindromicity can Applie D to the natural numbers in any numeral system. Consider a number N > 0 in base b >= 2, where it's written in standard notation with k+1 digits ai as the sum of (ai) for I from 0 to K. Here, as usual, 0 <= ai < b for all I and ak is Non-zero. Then N are palindromic if and only if Ai = ak-i for All I. Zero is written 0 in any base and is also palindromic by definition.
Given any non-negative decimal integer N and a base B, you were supposed to tell if N is a palindromic number in base B.
Input Specification:
Each input file contains the one test case. Each case consists of a non-negative numbers n and b, where 0 <= n <= 9 is the decimal number and2 <= b <= 9 is thebase. The numbers is separated by a space.
Output Specification:
For each test case, the first print in the one line "Yes" if N is a palindromic number in base B, or "No" if not. Then on the next line, print N as the number in base B in the form "ak ak-1 ... a0". Notice that there must is no extra space at the end of output.
Sample Input 1:
27 2
Sample Output 1:
Yes1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No4 4 1
Source: >
#include<iostream>
#include<vector>
#include<stdio.h>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
vector<int> num;
bool CheckSeq() {
Span class= "KWD" >for ( int i = 0 I < num size () / 2 + 1 I ++) {
if (num[i] != num[num.size() - i - 1])
return false;
}
return true;
}
int main(void) {
int n, k;
cin >> n >> k;
int yushu;
while (true)
{
yushu = n%k;
num.push_back(yushu);
n = n / k;
if (n == 0)
break;
}
reverse(num.begin(), num.end());
if (CheckSeq() == false) {
cout << "No" << endl;
}
else
cout << "Yes" << endl;
for (int i = 0; i < num.size(); i++) {
cout << num[i];
if (i != num.size() - 1)
cout << " ";
}
return 0;
}
From for notes (Wiz)
1019. General Palindromic number (20)