2012-11-30 16:07:04Morris

[UVA][數學] 10830 - A New Function

Problem A
A New Function

Input File:
Standard Input

Output: Standard Output

 

We all know that any integer number N is divisible by 1 and N. That is why these two numbers are not the actual divisors of any numbers. The function SOD(n) (Sum of divisors) is defined as the summation of all the actual divisors of an integer number n. For example SOD(24)=2+3+4+6+8+12=35. The function CSOD(n) (cumulative SOD) of an integer n, is defined as below:

.

 

Given the value of n, your job is to find the value of CSOD(n).

 

Input

The input file contains at most 50 lines of input. Each line contains an integer n (0≤n≤2000000000). Input is terminated by a line where the value of n=0. This line should not be processed.

 

Output

For each line of input produce one line of output. This line should contain the serial of output followed by the value of CSOD(n). Look at the output for sample input for details. You can safely assume that any output number fits in a 64-bit signed integer.

 

Sample Input                               Output for Sample Input

2
100
200000000
0
 
Case 1: 0
Case 2: 3150

Case 3: 12898681201837053


Problem setter: Shahriar Manzoor

Special Thanks: Mohammad Sajjad Hossain


事實上這題很容易看出與 H() 有點像,
反向找出 n/l == n/r 此時 ans += (n/r)*(r-l+1)*(r+l)/2;


#include <stdio.h>

int main() {
    long long n, i;
    int cases = 0;
    while(scanf("%lld", &n) == 1 && n) {
        long long ans = 0, r = n, l, m;
        //long long sum = 0;
        while(r > 1) {
            m = n/r;
            l = n/(m+1)+1;
            ans += m*(r-l+1)*(r+l)/2;
            r = l-1;
        }
        /*for(i = 2; i <= n; i++) {
            sum += i*(n/i);
        }*/
        printf("Case %d: %lld\n", ++cases, ans - n*(n+1)/2+1);
    }
    return 0;
}