[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 ...
随机推荐
- LBA(逻辑区块地址)及PBA(物理区块地址)
LBA,全称为Logical Block Address,是PC数据存储装置上用来表示数据所在位置的通用机制,我们最常见到使用它的装置就是硬盘.LBA可以指某个数据区块的地址或者某个地址上所指向的数据 ...
- QReadWriteLock上锁容忍的等待时间是多久?
非递归上锁情况下,同一个锁,已经被锁过一次,那么另外一个线程尝试上锁,会被挡在外面,但是会被挡多久呢?挡一分钟会被崩溃,还十分钟,还是永久等待而不崩溃(希望如此)?还是会立刻崩溃?因为不可以重复上锁. ...
- Android利用Fiddler进行网络数据抓包,手机抓包工具汇总
Fiddler抓包工具 Fiddler抓包工具很好用的,它可以干嘛用呢,举个简单例子,当你浏览网页时,网页中有段视频非常好,但网站又不提供下载,用迅雷下载你又找不到下载地址,这个时候,Fiddler抓 ...
- JQuery DOM HighLighter (it's a basic "Inspect element" simple implementation to mimic what webkit inspector and firebug do)
JQuery DOM HighLighter (it's a basic "Inspect element" simple implementation to mimic what ...
- poj 2406 Power Strings(KMP变形)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28102 Accepted: 11755 D ...
- opengl模板缓冲区
相信大家有些人对opengl的模板缓冲区不是很理解,包括我最开始也是,opengl的模板缓冲区其实就是采用过滤的技术来控制那些颜色可以绘制,那些不能进行绘制.这里的过滤技术也就是我们的一个控制方法,主 ...
- JAVA学习第一课(初识JAVA)
PS:退ACM集训队了,自己也疯玩了两天,后天就开学了,就正式大二了,该收收心好好学习啦 ...
- 某IT校招笔试
前言 博主明天上午9点还有面试,今天突然看到某大牌IT公司笔试题目,必须做一下了 题目 1.假设把整数关键码K散列到N个槽列表,以下哪些散列函数是好的散列函数 A: h(K)=K/N; B: h(K) ...
- [学习笔记]今天开始学HTML5!
1,href和src的区别:href有“连接,引用”之意,指两者的连接关系,如<a href=""></a>,<link href="**. ...
- 10,随机等概率的输出m个不重复的数
今天看到一段代码,可以从0.....n-1中随机等概率的输出m个不重复的数(n远远大于m).遂记录下来. 首先,产生随机数,不免要用到srand,rand函数.先简单介绍下两个函数. 1,void s ...