Chef and the Dual Palindromes

Правка en2, от ironman7453, 2015-08-25 20:34:00

This problem was given at https://www.codechef.com/COOK61.

Problem link: DUALPAL

Problem statement:

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).

Input 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.

Output 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.

Constraints

1 ≤ T ≤ 5

2 ≤ B1 < B2 ≤ 16

Any idea how to approach the problem?

Теги palindrome, number theory

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский ironman7453 2015-08-25 21:20:03 1 Tiny change: 'ess than 260 for the' -> 'ess than 2^60 for the'
en3 Английский ironman7453 2015-08-25 20:34:37 7 (published)
en2 Английский ironman7453 2015-08-25 20:34:00 4 Tiny change: 'straints\n1 ≤ T ≤ 5\n2 ≤ B1 <' -> 'straints\n\n1 ≤ T ≤ 5\n\n2 ≤ B1 <' (saved to drafts)
en1 Английский ironman7453 2015-08-25 20:33:37 1333 Initial revision (published)