Sum of product of x and y with floor(n/x) = y
Basic Accuracy: 75.24% Submissions: 6197 Points: 1

Given a positive integer n. Find the sum of product of x and y such that floor(n/x) = y .
 

Example 1:

Input: n = 5
Output: 21
Explanation: Following are the possible 
pairs of (x, y):
(1, 5), (2, 2), (3, 1), (4, 1), (5, 1).
So, 1*5 + 2*2 + 3*1 + 4*1 + 5*1 
   = 5 + 4 + 3 + 4 + 5 
   = 21.

Example 2:

Input: n = 10
Output: 87
Explanation: Sum of product of all 
possible pairs of (x, y) is 87.

 

Your Task:
You don't need to read or print anything. Your task is to cpmplete the function sumofproduct() which takes n as input parameter and returns the sum of product of all possible pairs(x, y).

 

Expected Time Complexity: O(n)
Expected Space Compelxity: O(1)

 

Constraints:
1 <= n <= 106

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Sum of product of x and y with floor(n/x) = y

Output Window