Gym 101047B  Renzo and the palindromic decoration

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

standard input/output

At the ruins of Wat Phra Si Sanphet (วดพระศรสรรเพชญ), one can find famous inscriptions that have only recently been decoded. Several numbers written using Thai numerals decorate these ruins.

A couple of years ago, the famous Peruvian researcher Renzo "el intrépido" Morales found out that most numbers found at the ruins are palindromic, that is, they represent the same number when read backwards. For instance, 171 is palindromic, whereas 17 is not.

Intrigued by the existence of non palidromic numbers as decorations in the ruins, Renzo found out that, while these numbers are not palindromic when represented in base 10 (which is the base used in the Thai numeral system), they are palindromic when represented in another base. For b > 0, the base-b representation of a number N is the sequence amam - 1... a1a0 so that 0 ≤ ai ≤ b - 1 for each 0 ≤ i ≤ mam ≠ 0, and

ambm + am - 1bm - 1 + ... + a1b + a0 = N.For the previous example, the base-2 representation of 17 is 10001, which is palindromic.

To validate his discovery, Renzo wants you to write a program that takes a number represented in base 10 and checks in which bases from 2 to 16 such number has a palindromic representation.

Input

The first line has a single integer T, the number of test cases.

Each test case has a single line with an integer N written in base 10.

Output

For each test case, print in a single line a space-separated list of integers, from 2 to 16 and in increasing order, of the bases for which the representation of N is palindromic. If N does not have a palindromic representation for any of the bases from 2 to 16, print -1.

Limits

  • 0 ≤ T ≤ 103
  • 0 ≤ N < 231

Sample Input

Input
  1. 2
    17
    2570
Output
  1. 2 4 16
    4 16
  1. /*/
  2. 题意:
  3. 给你一个数,将这个数换成2~16进制的任何数,如果换成其他进制的数之后能够形成一个回文数【不懂去百度】就输出这个进制。
  4.  
  5. 如果一个都不能形成回文数,输出 -1 。
  6.  
  7. 模拟短除法,暴力解题。
  8.  
  9. AC代码:
  10. /*/
  1. #include"algorithm"
  2. #include"iostream"
  3. #include"cstring"
  4. #include"cstdio"
  5. #include"string"
  6. #include"vector"
  7. #include"queue"
  8. #include"cmath"
  9. using namespace std;
  10. #define FK(x) cout<<"["<<x<<"]"<<endl
  11. #define memset(x,y) memset(x,y,sizeof(x))
  12. #define memcpy(x,y) memcpy(x,y,sizeof(x))
  13. #define bigfor(x) for(int qq=1;qq<=x;qq++)
  14. #define FIN freopen("input.txt","r",stdin)
  15. #define FOUT freopen("output.txt","w+",stdout)
  16.  
  17. int ans[20];
  18.  
  19. bool ok(int n,int i) {
  20. memset(ans,0);
  21. int erear=0;
  22. while(n) {
  23. ans[erear++]=n%i;
  24. n/=i;
  25. }
  26. for(int j=0; j<erear/2; j++) {
  27. if(ans[j]!=ans[erear-1-j])return 0;
  28. }
  29. return 1;
  30. }
  31.  
  32. int main() {
  33. int T;
  34. scanf("%d",&T);
  35. bigfor(T) {
  36. int n;
  37. scanf("%d",&n);
  38. int first=1;
  39. int sign=1;
  40. for(int i=2; i<17; i++) {
  41. if(ok(n,i)) {
  42. if(first) first=0;
  43. else printf(" ");
  44. printf("%d",i);
  45. sign=0;
  46. }
  47. }
  48. if(sign)puts("-1");
  49. else puts("");
  50. }
  51. return 0;
  52. }
  1.  

  

  1.  

ACM: Gym 101047B Renzo and the palindromic decoration - 手速题的更多相关文章

  1. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  2. 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题

    表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3   描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...

  3. (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题)

    layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题) author: " ...

  4. ACM: Gym 100935F A Poet Computer - 字典树

    Gym 100935F A Poet Computer Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d &am ...

  5. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  6. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  7. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  8. ACM: Gym 100935B Weird Cryptography - 简单的字符串处理

    Weird Cryptography Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  9. ACM: Gym 100935G Board Game - DFS暴力搜索

    Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100 ...

随机推荐

  1. CentOS添加用户并加入sudo权限

    # 新增用户 useradd username # 设置密码 passwd username # 加入sudo ## 打开sudo配置文件 visudo ## 找到下面这两行,并在下面新增红色部分 # ...

  2. 用遗传算法GA改进CloudSim自带的资源调度策略

    首先理解云计算里,资源调度的含义: 看了很多云计算资源调度和任务调度方面的论文,发现很多情况下这两者的意义是相同的,不知道这两者是同一件事的不同表述还是我没分清吧,任务调度或者资源调度大概就是讲这样一 ...

  3. C#多线程 线程的启动

    在实例化Thread的实例,需要提供一个委托,在实例化这个委托时所用到的参数是线程将来启动时要运行的方法.在.net中提供了两种启动线程的方式,一种是不带参数的启动方式,另一种是带参数的启动的方式. ...

  4. 【krpano】加密XML手动解密分析

    krpano允许对XML文件进行加密,对XML进行相应的保护.加密分为两种,第一种为公共加密,即允许其他krpano全景读取该XML,而另一种为私有加密,仅允许加密的用户读取XML.两种加密方式的算法 ...

  5. ztree-demo 2

    <!DOCTYPE html> <HTML> <HEAD> <TITLE> ZTREE DEMO - Async</TITLE> <m ...

  6. sha1散列(C语言)

    /** * \file sha1.h * * \brief SHA-1 cryptographic hash function * * Copyright (C) 2006-2010, Brainsp ...

  7. 【转】Linux makefile 教程 非常详细,且易懂

    From: http://blog.csdn.net/liang13664759/article/details/1771246 最近在学习Linux下的C编程,买了一本叫<Linux环境下的C ...

  8. [知识笔记]Java 基本数据类型的大小、取值范围、默认值

    数据类型 大小(字节) 范围 默认值 boolean 1/8(1bit) true/false false byte 1 -128~127 (-2^7~2^7-1) 0 short 2 -32768~ ...

  9. Docker和Docker-compose安装教程以及docker-elk,docker-storm安装教程

    此安装教程仅供我自己安装配置时查看,其他的人不可以偷看!!! 安装Docker 1. Update package information, ensure that APT works with th ...

  10. 【Java EE 学习 71 下】【数据采集系统第三天】【分析答案实体】【删除问题】【删除页面】【删除调查】【清除调查】【打开/关闭调查】

    一.分析答案实体 分析答案实体主要涉及到的还是设计上的问题,技术点几乎是没有的.首先需要确定一下答案的格式才能最终确定答案实体中需要有哪些属性. 答案格式的设计是十分重要的,现设计格式如下: 在表单中 ...