题目链接: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. eclipse及Java常用问题及解决办法汇总

    junit-test 我觉得这点比idea好用,可以直接选中要测试的方法名,右击run as即可 http://www.cnblogs.com/brolanda/p/4532779.html 打开您的 ...

  2. CF R303 div2 C. Woodcutters

    C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. [转]maven入门

    http://wentao365.iteye.com/blog/903396 Maven是一个采用纯Java编写的开 源项目管理工具.Maven采用了一种被称之为project object mode ...

  4. zombie-phantom

    zombie-phantom zombie-phantom Provides a Zombie.js shim around the PhantomJS Headless Browser. npm i ...

  5. josscrowcroft / Simple-JavaScript-DOM-Inspector

    josscrowcroft / Simple-JavaScript-DOM-Inspector josscrowcroft / Simple-JavaScript-DOM-Inspector

  6. Sonar入门学习

    最近在学习Sonar,配置了好几天,才搭建起来环境,为自己的学习能力感到汗颜,赶紧在此记录一下,所谓好记性不如烂笔头. 1.Sonar介绍 Sonar是一个用于代码质量管理的开源平台,用于管理Java ...

  7. android项目 之 记事本(12) ----- 图片的等比例缩放及给图片加入边框

    本文是自己学习所做笔记.欢迎转载,但请注明出处:http://blog.csdn.net/jesson20121020 在Android的UI开发中常常会遇到图片的缩放,就比方记事本,如今的图片都比較 ...

  8. 汉诺塔 python版

    汉诺塔问题:如果将n个盘子(由小到大)从a通过b,搬到c,搬运过程中不能出现小盘子在大盘子下面的情况. 思路分析:假设前要移动第100个盘子,分两步走,移动第99个:再移动第100个:而要移动第99个 ...

  9. apache域名重定向301跳转 .htaccess的写法

    RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} ^baidu.com$ [NC] RewriteRule ^(.*)$ http://w ...

  10. php制作数据字典

    /** * 生成mysql数据字典 */ header("Content-type:text/html;charset=utf-8"); // 配置数据库 $database = ...