uva 10830 A New Function

来源:互联网 发布:淘宝促销活动 编辑:程序博客网 时间:2024/06/14 11:14
/**   Author: johnsondu*   time: 2013-4-25*   problem: uva 10830 - A New Function*   url: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1771*   solution: http://www.algorithmist.com/index.php/UVa_10830*       */#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <queue>#include <cstring>using namespace std ;#define LL long long#define inf 0xfffffff#define M 1500005#define N 200000#define T 1005#define max(x, y) (x > y ? x : y)#define min(x, y) (x < y ? x : y)LL n, num ;LL solve (){    LL ans = 0, lf, rt ;    for (int i = 2; i*i <= n; i ++)        ans += i * (n/i - 1) ;    for (int i = 2; i * i < n; i ++)    {        lf = n / (i+1) + 1 ;        rt = n / i ;        if (lf > i)            ans += (lf + rt) * (rt-lf+1) / 2 * (i-1) ;    }    return ans ;}int main (){    int tcase, cs = 1 ;    //freopen ("data.txt", "r", stdin) ;    scanf ("%d", &tcase) ;    while (tcase --)    {        scanf ("%lld", &n) ;        printf ("Case %d: %lld\n", cs++, solve ()) ;    }    return 0 ;}