Sherlock and Squares, sherlocksquares
// Link
Https://www.hackerrank.com/challenges/sherlock-and-squares
1 from math import sqrt # What to use, what to introduce, reduce waste and error possibilities 2 3 4 def main (): 5 t = int (raw_input ()) 6 for _ in range (t): 7 squares = 0 8 a, B = map (int, raw_input (). strip (). split ('') 9 temp = int (sqrt (a) # Set the start point of temp to 10 while temp ** 2 <= B: # Stuck upper and lower boundary 11 if temp ** 2> = a: 12 squares + = 113 temp + = 114 15 print squares16 17 main ()
Learning
ABSTRACT To the essence, start Reverse Thinking
Reverse thinking:
Positive thinking:
Each number needs to be opened. If you note the Input requirements, you will find that this amount is quite large.
Reverse:
Start with the boundary value next to square a. The tested value after square is not in the range of [a, B], because the increase of Square is quite fast.