24h購物| | PChome| 登入
2012-11-30 16:07:04| 人氣1,411| 回應0 | 上一篇 | 下一篇

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

推薦 0 收藏 0 轉貼0 訂閱站台

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;
}

 

台長: Morris
人氣(1,411) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][模擬] 10686 - SQF Problems
此分類上一篇:[UVA][烏龜塔][Greedy解] 10154 - Weights and Measures

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文