We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Sherlock and Squares
Sherlock and Squares
+ 0 comments C++ code solution
int squares(int a, int b) { int count = 0; int sqrta = sqrt(a); int sqrtb = sqrt(b); if (sqrta * sqrta - a == 0){ for (int i = sqrta; i <= sqrtb; i++){ count++; } } else { for (int i = sqrta + 1; i <= sqrtb; i++){ count++; } } return count; }
+ 0 comments JavaScript
function squares(a, b) { // Write your code here let squares = 0 for (let i = a; i <= b; i++) { if (Math.sqrt(i) % 1 == 0) { i += Math.sqrt(i) * 2 squares++ } } return squares }
+ 0 comments JavaScript
function squares(a, b) { // Write your code here let lowerLimit =Number.isInteger(Math.sqrt(a))?Math.sqrt(a)-1 :Math.floor(Math.sqrt(a)) ; let upperLimit = Math.floor(Math.sqrt(b)); return upperLimit-lowerLimit }
+ 0 comments def squares(a, b): count = 0 root_val = int(math.sqrt(a)) num = root_val if root_val**2 >= a else root_val+1 while num**2 <= b: count += 1 num +=1 return count
+ 0 comments Python 3
def squares(a, b): # Write your code here c = math.ceil(a**(1/2)) d = math.floor(b**(1/2)) return d - c + 1
Load more conversations
Sort 1417 Discussions, By:
Please Login in order to post a comment