Chef and the Dual Palindromes
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian as well.
A number is called a Dual Palindrome if it's representation in bases B1 and B2 are both palindromes. e.g. Let B1 = 3, B2 = 4, then number 130 (in base 10) will be called a Dual Palindrome, as it is palindrome in base 3 (11211) as well as in base 4 (2002). However, it is not a Dual Palindrome for B1 = 3 and B2 = 5 as it's not a palindrome in base 5(1010).
Given two integers B1 and B2, Chef wants to find Dual Palindromes less than 260. If there are more than 1000 Dual Palindromes, then output the first 1000 only (these numbers should be in base 10).
The fine line of the input contains an integer T denoting the number of test cases.
Each test case consists of a single line containing two space separated integers: B1 and B2, respectively.
For each test case, output a list of space separated integers which are Dual Palindromes less than 260 for the input bases. If there are more than 1000 Dual Palindromes, then output the first 1000 only. The numbers should be printed in an ascending order.
- 1 ≤ T ≤ 5
- 2 ≤ B1 < B2 ≤ 16
Input: 1 2 3 Output: 1 6643 1422773 5415589 90396755477 381920985378904469
Source limit for the problem is 8000B instead of usual 50000B.
|Tags||backtracking cook61 hard maths rustinpiece|
|Time Limit:||8 sec|
|Source Limit:||8000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.4, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.