Count Distinct Squares and Cubes Python
PROGRAM TO COUNT NUMBER OF DISTINCT SQUARES AND CUBES UP TO N
OUTPUT
Number of squares and cubes is 5
CREDITS: https://www.geeksforgeeks.org/program-to-count-number-of-distinct-squares-and-cubes-upto-n/
PROGRAM TO COUNT NUMBER OF DISTINCT SQUARES AND CUBES UP TO N
import
math
# for sqrt()
# Function to count the number
# of perfect squares and cubes
def
countSC(N):
res
=
(
int
(math.sqrt(N))
+
int
(N
*
*
(
1
/
3
))
-
int
(math.sqrt(N
*
*
(
1
/
3
))))
return
res
# Driver code
N
=
20
print
(
"Number of squares and cubes is"
,
countSC(N))OUTPUT
Number of squares and cubes is 5
CREDITS: https://www.geeksforgeeks.org/program-to-count-number-of-distinct-squares-and-cubes-upto-n/
Comments
Post a Comment