<?php
$answer = 0;
for($i = 1 ; $i < 1000000 ; $i += 2)
{
// 2進数、10進数において回文数か否か
if(check_kaibun($i) and check_kaibun(decbin($i)))
{
$answer += $i;
}
}
echo $answer;
function check_kaibun($i)
{
$top = strlen($i) - 1;
$bottom = 0;
$flag = true;
while($top > $bottom )
{
// 一致しているか否かを調べる
if(substr($i,$top,1) == substr($i,$bottom,1))
{
$top --;
$bottom++;
}
else
{
$flag = false;
break;
}
}
return $flag;
}
?>