View Discussion Show Improve Article Save Article View Discussion Improve Article Save Article Given a number N, the task is to find No. of perfect Squares and perfect Cubes from 1 to a given integer, N ( Both Inclusive).
Naive Approach:
Below is the implementation of above approach: C++
Java
Python3
C#
PHP
Javascript
Output Number of squares and cubes is 5 Time Complexity: O(N) Efficient Approach:
Below is the implementation of the above approach: C++
Java
Python3
C#
PHP
Javascript
Output Number of squares and cubes is 5 Time Complexity: O(1) Square Roots in Mathematics The Python ** operator is used for calculating the power of a number. In this case, 5 squared, or 5 to the power of 2, is 25. The square root, then, is the number n, which when multiplied by itself yields the square, x. In this example, n, the square root, is 5. The pow() function from the Python math module also lets us compute the cube of a number. The pow() function takes two numbers as input, the first number is the base and the second number is the exponent. sqrt() function is an inbuilt function in Python programming language that returns the square root of any number. Syntax: math. sqrt(x) Parameter: x is any number such that x>=0 Returns: It returns the square root of the number passed in the parameter. |