Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

n numbers sum

# Not used any loop:
# Time complexity = O(1)
# Space Complexity = O(1)

# n = 10
n = int(input())
print("N-th only even numbers sum =",(n//2)*((n//2)+1))
print("N-th only odd numbers sum =",(n//2)**2)
print("N-th all numbers sum =",n*(n+1)//2)

#output:
# N-th only even numbers sum = 30
# N-th only odd numbers sum = 25
# N-th all numbers sum = 55
 
PREVIOUS NEXT
Tagged: #numbers #sum
ADD COMMENT
Topic
Name
6+5 =