1019 General Palindromic Number (20 分)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.

Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N>0 in base b≥2, where it is written in standard notation with k+1 digits a​i​​ as ∑​i=0​k​​(a​i​​b​i​​). Here, as usual, 0≤a​i​​<b for all i and a​k​​ is non-zero. Then N is palindromic if and only if a​i​​=a​k−i​​ for all i. Zero is written 0 in any base and is also palindromic by definition.

Given any positive decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.

Input Specification:

Each input file contains one test case. Each case consists of two positive numbers N and b, where 0<N≤10​9​​ is the decimal number and 2≤b≤10​9​​ is the base. The numbers are separated by a space.

Output Specification:

For each test case, first print in one line Yes if N is a palindromic number in base b, or No if not. Then in the next line, print N as the number in base b in the form "a​k​​ a​k−1​​ ... a​0​​". Notice that there must be no extra space at the end of output.

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

水题:进制转换,判断是否回文

 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-24-01.08.29
 * Description : A1019
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;
 ;
 bool judge(int s[],int len){
     ;i<len;i++){
         ]){
             return false;
         }
     }
     return true;
 }
 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int a,n;
     scanf("%d%d",&a,&n);
     ,s[maxn]={};
     do{
         s[num++]=a%n;
         a/=n;
     }while(a);
     if(judge(s,num)){
         printf("Yes\n");
     }
     else{
         printf("No\n");
     }
     ;i>=;i--){
         printf("%d",s[i]);
         ) printf(" ");
     }
     ;
 }

1019 General Palindromic Number (20 分)的更多相关文章

  1. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  2. PAT Advanced 1019 General Palindromic Number (20 分)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  3. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) (进制转换,回文数)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  4. 1019 General Palindromic Number (20 分)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  5. 【PAT甲级】1019 General Palindromic Number (20 分)

    题意: 输入两个正整数n和b(n<=1e9,2<=b<=1e9),分别表示数字的大小和进制大小,求在b进制下n是否是一个回文串,输出“Yes”or“No”,并将数字n在b进制下打印出 ...

  6. 1019 General Palindromic Number (20)(20 point(s))

    problem A number that will be the same when it is written forwards or backwards is known as a Palind ...

  7. 1019. General Palindromic Number (20)

    生词以及在文中意思 forward 向前地 backward 向后地 palindromic 回文的 base 基数(如十进制的10 和二进制的2) numeral system 数制 decimal ...

  8. PAT (Advanced Level) 1019. General Palindromic Number (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  9. PAT甲题题解-1019. General Palindromic Number (20)-又是水题一枚

    n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...

  10. PAT A1019 General Palindromic Number (20 分)

    AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...

随机推荐

  1. vmware Esxi 回收Thin模式磁盘空间

    本文来自:https://blog.csdn.net/happyfreeangel/article/details/85075179 第一部分 回收Thin模式磁盘空间背景:在使用Thin模式的磁盘, ...

  2. 2019.1.3 WLAN 802.11 a/b/g PHY Specification and EDVT Measurement I - Transmit Power Level

    This lecture provides the WLAN hardware engineer the essential knowledge of IEEE 802.11 a/b/g physic ...

  3. Hibernate和Spring整合出现懒加载异常:org.hibernate.LazyInitializationException: could not initialize proxy - no Session

    出现问题:  SSH整合项目里,项目目录结构如下: 在EmployeeAction.java的list()方法里将employees的list放入到request的Map中. EmployeeActi ...

  4. JavaScript事件漫谈

    内容概要: event对象,事件在多个浏览器中的兼容,事件的传播机制,JS自定义事件,jQuery的自定义事件的绑定与触发 Event对象 Event对象属于HTML DOM对象.Event 对象代表 ...

  5. linux 简单常用命令

    kill -3 pid就是发送信号3也就是SIGQUIT给进程pid.kill -9 就是发信号9也就是SIGKILL. pwd: 打印当前工作目录ls:默认显示当前工作目录内容cd:改变当前工作目录 ...

  6. Linux 内核链表实现和使用(一阴一阳,太极生两仪~)

    0. 概述 学习使用一下 linux 内核链表,在实际开发中我们可以高效的使用该链表帮我们做点事, 链表是Linux 内核中常用的最普通的内建数据结构,链表是一种存放和操作可变数据元 素(常称为节点) ...

  7. OK335xS Linux Qt make: icpc: Command not found

    OK335xS Linux Qt make: icpc: Command not found 一.出错现象: make: icpc: Command not found make: *** [main ...

  8. 习题3.5 求链表的倒数第m个元素(20 分)浙大版《数据结构(第2版)》题目集

    请设计时间和空间上都尽可能高效的算法,在不改变链表的前提下,求链式存储的线性表的倒数第m(>0)个元素. 函数接口定义: ElementType Find( List L, int m ); 其 ...

  9. LG3898 [湖南集训]大新闻

    题意 题目描述 **记者弄了个大新闻,这个新闻是一个在 [0,n) 内等概率随机选择的整数,记其为 x.为了尽可能消除这个大新闻对公众造成的不良印象,我们需要在 [0,n)内找到某一个整数 y,使得 ...

  10. UVA10590 Boxes of Chocolates Again

    题意 将正整数N拆分成若干个正整数之和,问有多少种不重复的拆分方案. \(n \leq 5000\) 分析 用f(i,j)表示将i拆成若干个数字,最大的那个数字(即最后一个数)不超过j的方案数. 转移 ...