[UVA][] 10830 - A New Function@Morris' Blog|PChome Online 人新台
2012-11-30 16:07:04| 人1,442| 回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,442) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA][模] 10686 - SQF Problems
此分上一篇:[UVA][塔][Greedy解] 10154 - Weights and Measures

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86