Table Summation

Easy
0/40
0 upvote

Problem statement

You are given an integer 'N'.


Return the summation of its multiplication table up to 10.


For Example :
Let 'N' = 5.
The multiplication table of 5 up to 10 is: 5, 10, 15, 20, 25, 30, 35, 40, 45, 50.
The summation is 5 + 10 + 15 + 20 + 25 + 30 + 35 + 40 + 45 + 50 = 275.
Therefore, the answer is 275.
Detailed explanation ( Input/output format, Notes, Images )
Input Format :
The first line contains a single integer 'N'.
Output Format :
Return the summation of the multiplication table of 'N' up to 10.
Note :
You don’t need to print anything. Just implement the given function.
Constraints :
1 <= 'N' <= 1000

Time Limit: 1 sec
Sample Input 1 :
7
Sample Output 1 :
385
Explanation of sample input 1 :
The multiplication table of 7 up to 10 is: 7, 14, 21, 28, 35, 42, 49, 56, 63, 70.
The summation is 7 + 14 + 21 + 28 + 35 + 42 + 49 + 56 + 63 + 70 = 385.
Thus, the answer is 385.
Sample Input 2 :
1
Sample Output 2 :
55
Hint

Recognize that the summation of the multiplication table can be expressed using the distributive property of multiplication over addition.

Approaches (1)
Math

Approach:

  • Factor out 'N' from the summation of its multiples.
    • The summation of the multiplication table of 'N' up to 10 can be written as: S=(N×1)+(N×2)+(N×3)+(N×4)+(N×5)+(N×6)+(N×7)+(N×8)+(N×9)+(N×10)
    • Using the distributive property, we can factor out 'N': S=N×(1+2+3+4+5+6+7+8+9+10)
  • The remaining series is the sum of the first 10 natural numbers, which has a direct mathematical formula.
    • The sum of the first 'k' natural numbers is given by the formula: 2k(k+1)​
    • In this case, k=10, so the sum of the first 10 natural numbers is: 210(10+1)​=210×11​=55
  • Therefore, the summation of the multiplication table of 'N' up to 10 is: S=N×55

Algorithm:

  • Return N * 55.
Time Complexity

O(1).

The calculation involves a constant number of arithmetic operations, independent of the value of 'N'. Thus, the overall time complexity is of the order O(1).

Space Complexity

O(1).

We are only using a few constant space variables to store the result. Thus, the overall space complexity is of the order O(1).

Code Solution
(100% EXP penalty)
Table Summation
Full screen
Console