Fair and Square (Large 1)
Time limit5sMemory limit512 MB
Count the integers in each interval [A, B] that are palindromes and the square of a palindrome.
- Level
Medium6 of 10
- Topics
- Math, Brute force, Binary search
- Solved
- No attempts yet
Problem
Little John likes palindromes and calls them fair. A palindrome is an integer that reads the same forwards and backwards, so 6, 11 and 121 are palindromes while 10, 12, 223 and 2244 are not. Leading zeroes do not count, so writing 010 = 10 does not make 10 a palindrome.
Little John also became interested in squares, so he defined a fair and square number: a number that is a palindrome and at the same time the square of a palindrome. For example 1, 9 and 121 are fair and square, because each one is a palindrome and each one is the square of 1, 3 and 11 respectively. On the other hand 16, 22 and 676 are not fair and square. 16 is not a palindrome, 22 is not a square, and 676 is a palindrome and a square, but its square root 26 is not a palindrome.
Given an interval, count how many fair and square numbers lie inside it.
Input
The first line contains the number of test cases . Each of the next lines contains two integers and separated by a space, the endpoints of one interval Little John is looking at.
Limits
Output
For each test case, print one line in the form "Case #x: y", where is the test case number starting from 1 and is the number of fair and square numbers with .