[Swust OJ 797]--Palindromic Squares(回文数水题)
题目链接:http://acm.swust.edu.cn/problem/797/
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.
A single line with B, the base (specified in base 10).
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.
| 10 |
|
1 1
2 4
3 9
11 121
22 484
26 676
101 10201
111 12321
121 14641
202 40804
212 44944
264 69696
|
#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(回文数水题)的更多相关文章
- Palindromic Squares 回文平方数
1.2.4 Palindromic Squares 回文平方数 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 139 Solved: 66[Submit ...
- LeetCode OJ Palindrome Number(回文数)
class Solution { public: bool isPalindrome(int x) { ,init=x; ) return true; ) return false; ){ r=r*+ ...
- CodeForces 548A Mike and Fax (回文,水题)
题意:给定一个字符串,问是不是恰好存在 k 个字符串是回文串,并且一样长. 析:没什么好说的,每次截取n/k个,判断是不是回文就好. 代码如下: #include<bits/stdc++.h&g ...
- yzoi1109&&viojs1042最小步数的一点看法——回文数
Description - 问题描述 有一天,雄霸传授本人风神腿法第一式:捕风捉影..............的步法(弟子一:堂主,你大喘气呀.风:你给我闭嘴.)捕风捉影的关键是换气(换不好就会大喘气 ...
- 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 ...
- 合工大OJ 1331 回文数
Description 一个正整数,如果从左向右读(称之为正序数)和从右向左读(称之为倒序数)是一样的,这样的数就叫回文数. 任取一个正整数,如果不是回文数,将该数与他的倒序数相加,若其和不是回文数, ...
- 2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- POJ2402 Palindrome Numbers 回文数
题目链接: http://poj.org/problem?id=2402 题目大意就是让你找到第n个回文数是什么. 第一个思路当然是一个一个地构造回文数直到找到第n个回文数为止(也许大部分人一开始都是 ...
- [LeetCode] Prime Palindrome 质数回文数
Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...
随机推荐
- for循环例子1、2、3
/* Name:for循环例子1.2.3 Copyright: By.不懂网络 Author: Yangbin Date:2014年2月12日 02:12:41 Description:该代码用来熟悉 ...
- 关于Android Launcher图标上面动态改变数字的实现
由于项目需要使用到类似小米应用商店的图标数字提示功能,谷歌百度了许多文章都没看到有真正意义上的实现(没有在国外网站上搜索),有实现在APP内部的一个ImageView上面更新数字的,当然这种太简单无非 ...
- Less基础教程
Less基础教程 less是较早出现的css预处理器. LESS API 参考 安装和使用 安装比较简单,通过nmp或bower安装即可. npm install less -g bower inst ...
- 转: 关于异步promises
迄今为止,可能每个JavaScript开发者和他们的祖母都听说过Promises.如果你没有,那么你即将会.promises的概念是由CommonJS小组的成员在 Promises/A规范 中提出来的 ...
- Hadoop基准测试(转载)
<hadoop the definitive way>(third version)中的Benchmarking a Hadoop Cluster Test Cases的class在新的版 ...
- VM 映像
让我们一起欢呼吧!随着最近Microsoft Azure运行时的发布,我们非常高兴地宣布发布 OS映像的继承性产品:新 VM映像.等一下-有些人可能会觉得这听起来有点耳熟.没错,一个月前在旧金山 ...
- [Docker]初次接触
Docker 初次接触 近期看了不少docker介绍性文章,也听了不少公开课,于是今天去官网逛了逛,发现了一个交互式的小教程于是决定跟着学习下. 仅仅是把认为重点的知识记录下来,不是非常系统的学习和笔 ...
- Mybatis上路_05-使用命令行自动生成【转】
http://my.oschina.net/vigiles/blog/125127 Mybatis上路_05-使用命令行自动生成 1人收藏此文章, 我要收藏 发表于1个月前(2013-04-24 ...
- Javascript初级学习总结
首先,在Html页面输出,使用document.write('内容'); <html> <head> <title></title> <scrip ...
- 虎扯:小众玩物 webkit家的滚动条
前面的话:对只有一种浏览器支持的属性,就不要出来秀咱前端同学,就像是早些年手机们的充电口一样,集各家所长,咱今天说的是webkit的滚动条样式,视乎只有webkit支持此项定义,有见识的前辈来辩.这玩 ...