let's start Code

Palindromic Squares

Palindromic Squares

 একটা সংখ্যার বেস দেওয়া থাকবে, ঐ বেসে  ১ থেকে ৩০০ এর মঝে যত প্যালিন্ড্রমিক   (সংখ্যাটির বর্গের)   নাম্বার আছে সেগুলা প্রিন্ট করতে হবে।
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define MAX 10005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
/*
ID: hasanma1
TASK: palsquare
LANG: C++
*/
char value[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
string Base(int n, int base)
{
string t;
while(n != 0){
t = value[n % base] + t;
n /= base;
}
// cerr << t << endl;
return t;
}
int main()
{
FASTIO
/*
//double start_time = clock();
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
//*/
///*
ofstream cout ("palsquare.out");
ifstream cin ("palsquare.in");
//*/
int base;
cin >> base;
//cerr << base<<endl;
for(int i = 1; i <= 300; i++){
//cerr << i+i << endl;
string N = Base(i, base);
string sq = Base(i*i, base);
string _new = sq;
reverse(_new.begin(), _new.end());
if(sq == _new){
cout << N << " "<<sq<<"\n";
}
}
//double end_time = clock();
//printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
return 0;
}
view raw palsquare.cpp hosted with ❤ by GitHub
Share:

Related Posts:

No comments:

Post a Comment

About

let's start CODE

Popular Posts