您的位置:首页 > 其它

uva 10830 A New Function

2013-04-26 17:03 218 查看
/*
*   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 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: