| Sum of f(x) |
| Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB |
| Total submit users: 194, Accepted users: 115 |
| Problem 11546 : No special judgement |
| Problem description |
| 令f(x)为x的所有约数之和,x的约数即可以被x整除的数,如f(24)=1+2+3+4+6+8+12+24=60),求 f(l) + f(l + 1) + …… + f(r) |
| Input |
| 第一行为一个整数T(T<=100000),表示数据的组数。 接下来T行,每行有两个整数l,r(1 <= l <= r <= 200000) |
| Output |
| 对每组数据,输出f(l)+f(l+1)+……+f(r) 的和 |
| Sample Input |
2 3 5 10 20 |
| Sample Output |
17 270 |
| Problem Source |
| HUNNU Contest |
解析:比赛时候就是怕超时,然后到死都在作死,结果别人的报告一出来,尼玛吓死人啊!!
注意:数据太大,要用64位。但是不知道什么情况,long long就WA了,用__int64才过的~~
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define LL __int64
using namespace std;
LL a[222222];
int main()
{
int i,j,k,l;
memset(a,0,sizeof(a));
for(i=1;i<=200000;i++)//不要怂,直接暴力打表
{
for(j=i;j<=200000;j+=i)
a[j]+=i;
a[i]+=a[i-1];//然后做递加保存,方便查找某一段的和
}
scanf("%d",&l);
while(l--&&scanf("%d%d",&i,&j))
{
printf("%I64d\n",a[j]-a[i-1]);
}
return 0;
}
原文:http://blog.csdn.net/jingdianitnan/article/details/46418115