题目链接:http://acm.swust.edu.cn/problem/797/

Time limit(ms): 1000      Memory limit(kb): 10000
 

Description

Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome.

Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that the square of N is palindromic when expressed in base B; also print the value of that palindromic square. Use the letters 'A', 'B', and so on to represent the digits 10, 11, and so on.

Print both the number and its square in base B.

Input

A single line with B, the base (specified in base 10).

 
Output

Lines with two integers represented in base B. The first integer is the number whose square is palindromic; the second integer is the square itself.

 
Sample Input
10
 
Sample Output
1 1
2 4
3 9
11 121
22 484
26 676
101 10201
111 12321
121 14641
202 40804
212 44944
264 69696
 
Hint
 
 
题目大意:一个n代表进制(n<=20),输出十进制数300以内的此时进制下的所有这个数的平方是回文数的所有数和它的平方
 
解题思路:直接转换判断就是了,判读回文可以利用回文数性质,在转换进制的数组中直接判断,具体的看代码
代码如下:
 #include<iostream>
using namespace std;
int n;
char str[] = "0123456789ABCDEFGHIJ";
void out(int x){
int a[], i = ;
while (x){
a[++i] = x%n;
x /= n;
}
for (; i; cout << str[a[i--]]);
}
void find(int x){
int a[], i = , s = x*x, t;
while (s){
a[++i] = s%n;
s /= n;
}
t = i;
for (; i&&a[i] == a[t - i + ]; --i); {
if (!i){
out(x), cout << ' ';
out(x*x), cout << endl;
}
}
}
int main()
{
cin >> n;
for (int i = ; i <= ; i++)
find(i);
return ;
}

[Swust OJ 797]--Palindromic Squares(回文数水题)的更多相关文章

  1. Palindromic Squares 回文平方数

    1.2.4 Palindromic Squares 回文平方数 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 139  Solved: 66[Submit ...

  2. LeetCode OJ Palindrome Number(回文数)

    class Solution { public: bool isPalindrome(int x) { ,init=x; ) return true; ) return false; ){ r=r*+ ...

  3. CodeForces 548A Mike and Fax (回文,水题)

    题意:给定一个字符串,问是不是恰好存在 k 个字符串是回文串,并且一样长. 析:没什么好说的,每次截取n/k个,判断是不是回文就好. 代码如下: #include<bits/stdc++.h&g ...

  4. yzoi1109&&viojs1042最小步数的一点看法——回文数

    Description - 问题描述 有一天,雄霸传授本人风神腿法第一式:捕风捉影..............的步法(弟子一:堂主,你大喘气呀.风:你给我闭嘴.)捕风捉影的关键是换气(换不好就会大喘气 ...

  5. 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 ...

  6. 合工大OJ 1331 回文数

    Description 一个正整数,如果从左向右读(称之为正序数)和从右向左读(称之为倒序数)是一样的,这样的数就叫回文数. 任取一个正整数,如果不是回文数,将该数与他的倒序数相加,若其和不是回文数, ...

  7. 2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. POJ2402 Palindrome Numbers 回文数

    题目链接: http://poj.org/problem?id=2402 题目大意就是让你找到第n个回文数是什么. 第一个思路当然是一个一个地构造回文数直到找到第n个回文数为止(也许大部分人一开始都是 ...

  9. [LeetCode] Prime Palindrome 质数回文数

    Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...

随机推荐

  1. java开发工具比较(16个工具修订版)

    1.JDK (Java Development Kit)Java开发工具集 SUN的Java不仅提了一个丰富的语言和运行环境,而且还提了一个免费的Java开发工具集(JDK).开发人员和最终用户可以利 ...

  2. sae上屏蔽错误显示并查看错误日志

    首先应用上线之前肯定要屏蔽错误显示的, 登录sae,点进去你的应用, 关闭之后进入日志管理当前的当前版本 在http中可以查看各个级别的日志记录了

  3. Candy----HDU4465----数学题

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4465 题目意思: 有两个箱子,每个箱子装有N个糖果 打开第一个箱子的概率是P,另外一个就是1-P 当小 ...

  4. Android中各种Adapter的使用方法

    1.概念 Adapter是连接后端数据和前端显示的适配器接口.是数据和UI(View)之间一个重要的纽带.在常见的View(ListView,GridView)等地方都须要用到Adapter.例如以下 ...

  5. redis的分布式解决方式--codis

    codis是豌豆荚开源的分布式server.眼下处于稳定阶段. 原文地址:https://github.com/wandoulabs/codis/blob/master/doc/tutorial_zh ...

  6. 在SSIS包中使用 Checkpoint从失败处重新启动包

    使用SSIS做ETL的过程中会遇到各种各样的错误,对于一些大数据量的Job失败以后我们不希望重新运行,因为重新运行的时间开销是非常大的,我们只希望从失败的部分开始运行,这样可以省去很多的时间. SSI ...

  7. MVC过滤器基本使用

        Action过滤器 /// <summary> /// 执行代码前执行 /// </summary> /// <param name="filterCo ...

  8. ZOJ 3080 ChiBi(spfa)

    ZOJ Problem Set - 3080 ChiBi Time Limit: 5 Seconds      Memory Limit: 32768 KB watashi's mm is so pr ...

  9. 如何交叉编译开源库-->编译c-ares库从失败到成功的过程[ocean]

    编译c-ares库从失败到成功的过程c-ares-master: apt-get install libtool   ####https://github.com/c-ares/c-ares ==== ...

  10. https tomcat 证书搭建

    首先生成证书说明 keytool -genkey -alias castest -keyalg RSA -keystore c:/keys/caskey 先让输入密码,密码必须记住,下面会用到 其中“ ...