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
2
17
2570
Output
2 4 16
4 16
/*/
题意:
给你一个数,将这个数换成2~16进制的任何数,如果换成其他进制的数之后能够形成一个回文数【不懂去百度】就输出这个进制。 如果一个都不能形成回文数,输出 -1 。 模拟短除法,暴力解题。 AC代码:
/*/
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdio"
#include"string"
#include"vector"
#include"queue"
#include"cmath"
using namespace std;
#define FK(x) cout<<"["<<x<<"]"<<endl
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define bigfor(x) for(int qq=1;qq<=x;qq++)
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout) int ans[20]; bool ok(int n,int i) {
memset(ans,0);
int erear=0;
while(n) {
ans[erear++]=n%i;
n/=i;
}
for(int j=0; j<erear/2; j++) {
if(ans[j]!=ans[erear-1-j])return 0;
}
return 1;
} int main() {
int T;
scanf("%d",&T);
bigfor(T) {
int n;
scanf("%d",&n);
int first=1;
int sign=1;
for(int i=2; i<17; i++) {
if(ok(n,i)) {
if(first) first=0;
else printf(" ");
printf("%d",i);
sign=0;
}
}
if(sign)puts("-1");
else puts("");
}
return 0;
}

  

 

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. webpack那些事儿

    webpack那些事儿01-webpack到底是什么 webpack那些事儿02-从零开始 webpack那些事儿03-热插拔 hot webpack那些事儿04-spa项目实战分析 webpack那 ...

  2. shell脚本重新挂载出问题的卷

    #!/bin/bash#卷的全路径示例#pathexample =mount -t cetusfs 127.0.0.1:/cinderv/var/lib/cinder/volumes/0f6a20f4 ...

  3. 第二篇 基于.net搭建热插拔式web框架(沙箱的构建)

    上周五写了一个实现原理篇,在评论中看到有朋友也遇到了我的问题,真的是有种他乡遇知己的感觉,整个系列我一定会坚持写完,并在最后把代码开源到git中.上一篇文章很多人看了以后,都表示不解,觉得不知道我到底 ...

  4. python拆分CANLog

    通过CANOE 导出的log通常有很多个ID的数据,如何才能找到某一个ID下的特殊的信号?利用python可以简单的进行这个步骤,代码如下: 说明: 最终的效果是将log信息,分不同的ID进行拆分,并 ...

  5. 用Burpsuite破解网站密码

    burpsuite专业版 一个网站 方法/步骤   1 切换至proxy选项卡的Option选项下,设置代理地址和端口:127.0.0.1:8080. 2 启动刚刚设置的代理 3 打开Internet ...

  6. ajax待总结项

    1.get与post请求的区别 get请求调用send方法发送数据时,会忽略传入的数据 2.post请求的三种方式区别 1.form表单 2.ajax 3.ajax + FormData 表格绘制,代 ...

  7. MyBatis:统计数量

    dao: /** * 统计商家的案例数量 * * @param shopId * @return */ long countByShopId(Long shopId); @Override publi ...

  8. mysql character set exception

    问题: 插入数据时,报了这样一个错误:“_mysql_exceptions.Warning: Incorrect string value: ‘\xE6\xB5\x81\xE8\xA1\x8C…’ f ...

  9. 463. Island Perimeter

    https://leetcode.com/problems/island-perimeter/ 在一个N×N的矩阵中,N<100,1代表岛,0代表海,岛内没有海,求岛的周长 [[0,1,0,0] ...

  10. SQL多表连接查询

    SQL多表连接查询 本文主要列举两张和三张表来讲述多表连接查询. 新建两张表: 表1:student  截图如下: 表2:course  截图如下: (此时这样建表只是为了演示连接SQL语句,当然实际 ...