Summation program
Practice
1 (1 votes)
Basic programming
Mathematics
Medium
Problem
30% Success 70 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a number \(N\). You are required to determine the value of the following function:
long long int solve(N)
{
ans=0;
for(i=1;i<=N;i++)
ans+=(N/i);
return ans;
}
All divisions are integer divisions(i.e. N/i is actually floor(N/i)).
Input format
- First line: \(T\) denoting the number of test cases
- Each of the next \(T\) lines: An integer \(N\)
Output format
For each test case, print the answer in a new line.
Input Constraints
\(1\le T \le 100 \)
\(1 \le N \le 10^{12}\)
Sample Input
1 5
Sample Output
10
Explanation
5/1=5
5/2=2
5/3=5/4=5/5=1
Answer=5+2+1+1+1=10
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:30
64 votes
Tags:
CombinatoricsEasyMathNumber theory
Points:30
3 votes
Tags:
MathematicsMediumOpenApprovedProbability and Statistics
Points:10
Tags:
Very-Easy
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor