ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
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 ≤ m, am ≠ 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
2
17
2570
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 - 手速题的更多相关文章
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题
表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...
- (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题)
layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题) author: " ...
- ACM: Gym 100935F A Poet Computer - 字典树
Gym 100935F A Poet Computer Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d &am ...
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 100935B Weird Cryptography - 简单的字符串处理
Weird Cryptography Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
随机推荐
- grep
http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856896.html
- mybatis批量删除提示类型错误
一. 这里主要考虑两种参数类型:数组或者集合. 而这点区别主要体现在EmpMapper.xml文件中标签的collection属性: 当collection="array"时,表名 ...
- 循环冗余码crc
待编码的有效信息组多项式:M(x) 生成多项式(产生校验码的多项式):G(x) 余数多项式:R(x) 商:Q(x) 生成多项式是四次的,所以某个多项式除以生成多项式的余式肯定是三次的,所以要加四位00 ...
- XP机器上WCF采用X509证书加密时IIS读取证书的授权
XP机器上WCF采用X509证书加密时IIS读取证书的授权 XP下的授权命令为:winhttpcertcfg -g -c LOCAL_MACHINE\My -s 证书名称 -a "ASPNE ...
- 关于计算机改名无法连接TFS的问题
今天重新导入了两台服务器, 修改了机器名,结果VS2012链接TFS报错 --------------------------- Microsoft Visual Studio ----------- ...
- iOS 系统数字键盘左下角加确定按钮
首先在 viewWillAppear 方法中注册监听相应的键盘通知,并且要在 viewWillDisappear 方法中注销通知- (void)viewWillAppear:(BOOL)animate ...
- 【转】网络编程socket基本API详解
转自:http://www.cnblogs.com/luxiaoxun/archive/2012/10/16/2725760.html socket socket是在应用层和传输层之间的一个抽象层,它 ...
- Mittag-Leffler定理,Weierstrass因子分解定理和插值定理
Mittag-Leffler定理 设$D\subset\mathbb C$为区域,而$\{a_{n}\}$为$D$中互不相同且无极限点的点列,那么对于任意给定的一列自然数$\{k_{n}\}$, ...
- Mysql Master-slave 主从配置
MySQL主从复制 场景描述:主数据库服务器:192.168.10.130,MySQL已经安装,并且无应用数据.从数据库服务器:192.168.10.131,MySQL已经安装,并且无应用数据. 2. ...
- LeetCode之263. Ugly Number
------------------------------------------------------------- 如果一个数的质因子只包括2,3,5,那么这个数n可以表示为:n=2x+3y+ ...