/**
 * The decimal number, 585 = 1001001001_(2) (binary), is palindromic in both bases.
 *
 * Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
 *
 * (Please note that the palindromic number, in either base, may not include leading zeros.)
 */
public class P36
{
    public static void main(String args[])
    {
        System.out.println("P36");
        
        int sum = 0;
        for (int i = 0; i <= 1000000; i++) {
            if (isPalindrome(Integer.toString(i)) && isPalindrome(Integer.toBinaryString(i))) {
                System.out.println(Integer.toString(i) + ":" + Integer.toBinaryString(i));
                sum += i;
            }
        } 
        
        System.out.println("Sum: " + sum);
    }
    
    private static boolean isPalindrome(String str)
    {
        char cArray[] = str.toCharArray();
        for (int i = 0; i < cArray.length / 2; i++) {
            if (cArray[i] != cArray[cArray.length - i - 1]) {
                return false;
            }
        }
        return true;
    }
}
