Description
If a number is read from left to right and from right to left, then this number is called "palindrome number". For example, 12321 is a palindrome number, and 77778 is not. Of course, the first and the end of a palindrome number should be nonzero, so 0220 is not a palindrome number.
In fact, there are some numbers (such as 21), which are not palindrome numbers in decimal, but are palindrome when other binary (such as 10101 at binary).
To compile a program, read from the file two decimal numbers n (1 <= n <=) S (0 < S < 10000) and then find out the first N is greater than s and in two or more binary (binary to decimal) is a palindrome number of decimal number, output to the file.
The solution for this problem does not require the use of integers larger than 32 bits
Format
Program NAME: Dualpal
INPUT FORMAT:
(File dualpal.in)
Only one row, separated by a space of two numbers n and S.
OUTPUT FORMAT:
(File dualpal.out)
n rows, one per line satisfies the above requirements, and outputs in order from small to large.
SAMPLE INPUT 3
SAMPLE OUTPUT
262728
#include <fstream>
using namespace std;
Ifstream cin ("dualpal.in");
Ofstream cout ("Dualpal.out");
int ini_t (int x,int B)
{
int a[20];
int b[20];
int l=0;
while (x!=0)
{
a[++l]=x%b;
x/=b;
}
for (int i=1;i<=l/2;i++)
{
if (A[i]!=a[l+1-i]) return 0;
}
return 1;
}
int main ()
{
int n,s;
cin>>n>>s;
int y=0;
for (int i=s+1;; i++)
{
int j1=0;
for (int j=2;j<=10;j++)
{
if (ini_t (i,j) ==1) j1++;
if (j1==2) break;
}
if (j1==2) {Y++;cout<<i<<endl;}
if (y==n) break;
}
System ("pause");
return 0;
}
Simulation questions