Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $n = (int)fgets(STDIN);
- for ($i=0; $i<$n; $i++)
- {
- preg_match('/(\d+) (\d+) (\d+)/', fgets(STDIN), $matches);
- $b = (int)$matches[1];
- $l = (int)$matches[2];
- $r = (int)$matches[3];
- $goodCount = 0;
- for ($num = $l; $num <= $r; $num++)
- {
- $numIsGood = true;
- $conv = base_convert($num, 10, $b);
- $counts = [];
- foreach (str_split($conv) as $digit)
- {
- if (!isset($counts[$digit])) { $counts[$digit] = 0; }
- $counts[$digit]++;
- }
- foreach ($counts as $count)
- {
- if (($count % 2) !== 0) {
- $numIsGood = false;
- break;
- }
- }
- if ($numIsGood) { $goodCount++; }
- }
- echo $goodCount . "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement