HUST-OJ-1669
2016-03-06 18:49
232 查看
L - Palindromes
Time Limit:1000MS Memory Limit:524288KB 64bit IO Format:%lld & %llu
Submit Status Practice HUST
1669
Description
Palindromes are numbers that read the same forwards as backwards. Like 12321.
Given a number base B (2 <= B <= 20), calculate all the number N( N no large than 300) such that N^2 is palindromic when expressed in base B.
Pay attention, 'A', 'B', and so on represent the digits 10, 11, and so on.
Print both the number and its square in base B.
Input
A single line with B.
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
Sample Output
题目不难 大意就是找出B进制的回文数,注意x和x^2都要回文数表示
#include<stdio.h>
int main()
{
int a[20],c[20];
int b,i,j,k,q,p;
scanf("%d",&b);
for(i=1;i<300;i++)
{
int x,y,flag=1;
x = i*i;
for(j=0;x!=0;j++)
{
a[j] = x%b;
x = x/b;
}
j--;
for(k=0;j>k;j--,k++)
if(a[j]!=a[k])
{
flag = 0;
break;
}
if(flag==1)
{
q = i;
for(j=0;q!=0;j++)
{
p = q%b;
c[j] = p;
q = q/b;
}
j--;
while(j>=0)
{
if(c[j]>9)
printf("%c",c[j]+55);
else
printf("%c",c[j]+48);
j--;
}
printf(" ");
x = i*i;
for(j=0;x!=0;j++){
y = x%b;
if(y>9)
printf("%c",y+55);
else
printf("%c",y+48);
x = x/b;
}
printf("\n");
}
}
}
Time Limit:1000MS Memory Limit:524288KB 64bit IO Format:%lld & %llu
Submit Status Practice HUST
1669
Description
Palindromes are numbers that read the same forwards as backwards. Like 12321.
Given a number base B (2 <= B <= 20), calculate all the number N( N no large than 300) such that N^2 is palindromic when expressed in base B.
Pay attention, 'A', 'B', and so on represent the digits 10, 11, and so on.
Print both the number and its square in base B.
Input
A single line with B.
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 44944264 69696
题目不难 大意就是找出B进制的回文数,注意x和x^2都要回文数表示
#include<stdio.h>
int main()
{
int a[20],c[20];
int b,i,j,k,q,p;
scanf("%d",&b);
for(i=1;i<300;i++)
{
int x,y,flag=1;
x = i*i;
for(j=0;x!=0;j++)
{
a[j] = x%b;
x = x/b;
}
j--;
for(k=0;j>k;j--,k++)
if(a[j]!=a[k])
{
flag = 0;
break;
}
if(flag==1)
{
q = i;
for(j=0;q!=0;j++)
{
p = q%b;
c[j] = p;
q = q/b;
}
j--;
while(j>=0)
{
if(c[j]>9)
printf("%c",c[j]+55);
else
printf("%c",c[j]+48);
j--;
}
printf(" ");
x = i*i;
for(j=0;x!=0;j++){
y = x%b;
if(y>9)
printf("%c",y+55);
else
printf("%c",y+48);
x = x/b;
}
printf("\n");
}
}
}
相关文章推荐
- FZU 2197 最小花费(思维题目)
- HDOJ 5100 Chessboard【规律】
- java并发编程(3):ThreadLocal
- 国内代码托管git-osc基础使用教程
- 运维日常工作
- Contains Duplicate
- python处理.seq文件
- Quartz2D - 画饼图
- css-照片瀑布流显示
- Arking advices | WPI
- Effective Java2读书笔记-对于所有对象都通用的方法(二)
- Linux学习笔记
- 概念的解释(二)
- 运维自动化架构
- 四则运算1(改)
- c语言面试题2
- HDU 2149 Public Sale
- 利用onDraw画出半圆按钮
- c语言之 malloc函数详解
- Android 通过JNI实现守护进程,使Service服务不被杀死