[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 ...
随机推荐
- USACO chapter1
几天时间就把USACO chapter1重新做了一遍,发现了自己以前许多的不足.蒽,现在的程序明显比以前干净很多,而且效率也提高了许多.继续努力吧,好好的提高自己.这一章主要还是基本功的训练,没多少的 ...
- 不允许在单例对象中创建Srping容器
spring.net在使用的时候,不允许在单例对象中创建Srping容器 需要将实例化模式转为单例singleton=“false”
- iOS面试题02-数据存储
1.如果后期需要增加数据库中的字段怎么实现,如果不使用CoreData呢? 回答:编写SQL语句来操作原来表中的字段 1>增加表字段 ALETER TABLE 表名 ADD COLUMN 字段名 ...
- 【转】adb.exe,start-server' failed -- run manually if necessary
[转]Android adb.exe程序启动不起来,如何处理 解决问题: 百度google大家多说的是任务管理器 kill掉adb 或者重启adb server,但我任务管理器就没有adb ,猜测是某 ...
- zoj 3710 Friends
#include<stdio.h> #include<string.h> ][],h; int main(int argc, char* argv[]) { int t,i,n ...
- BZOJ 3224: Tyvj 1728 普通平衡树(BST)
treap,算是模板题了...我中间还一次交错题... -------------------------------------------------------------------- #in ...
- struts的由来
当学习或工作时,有些同学会谈到熟悉struts.hibernate.spring等等框架,貌似熟悉这些框架是精通java的表现,但是我们应该首先弄明白为什么要学框架?是为了学习而学习?还是为了工作而学 ...
- relative、absolute和float
relative.absolute和float position:relative和position:absolute都可以改变元素在文档中的位置,都能激活元素的left.top.right.bo ...
- codeforces 451E. Devu and Flowers 容斥原理+lucas
题目链接 给n个盒子, 每个盒子里面有f[i]个小球, 然后一共可以取sum个小球.问有多少种取法, 同一个盒子里的小球相同, 不同盒子的不同. 首先我们知道, n个盒子放sum个小球的方式一共有C( ...
- 转几篇关于Android webView的网文
1,控件WebView显示网页 http://www.cnblogs.com/tinyphp/p/3858997.html http://blog.csdn.net/t12x3456/article/ ...