Palindromic Squares(模拟)

Description

回文数是指从左向右念和从右向左念都一样的数。如12321就是一个典型的回文数。 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下)且它的平方用B进制表示时是回文数的数。用’A’,’B’……表示10,11等等。

Input

共一行,一个单独的整数B(B用十进制表示)。

Output

每行两个B进制的符合要求的数字,第二个数是第一个数的平方,且第二个数是回文数。

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

题解:简单模拟。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define X (sqrt(5)+1)/2.0
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define ll long long
using namespace std;



int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=300;i++)
    {
        int s=i*i;
        int a[1111]={0},b[1111]={0},k=0;
        while(s)
        {
            a[k++]=s%n;
            s=s/n;
        }
        int ss=0;
        for(int j=0;j<=k/2;j++)
        {
            if(a[j]!=a[k-j-1])
                ss++;
        }
        if(ss==0)
        {
            int p=i,l=0;
            while(p)
            {
                b[l++]=p%n;
                p=p/n;
            }
            for(int j=l-1;j>=0;j--)
                if(b[j]>=10)
                    printf("%c",b[j]-10+'A');
                else
                    printf("%d",b[j]);
            printf(" ");
            for(int j=k-1;j>=0;j--)
                if(a[j]>=10)
                    printf("%c",a[j]-10+'A');
                else
                    printf("%d",a[j]);
            printf("\n");
        }
    }
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值