hunnu Sum of f(x)

http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11546&courseid=0

Sum of f(x)

Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 196, Accepted users: 118
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
#include<iostream>
#include<cstring>
#include<cstdio>
#define n  200005
using namespace std;
__int64 f[n],s[n];
int main()
{
      int i,j;

     memset(f,0,sizeof(f));
      memset(s,0,sizeof(s));
    for(i=1;i<=n;i++)
    {
         for(j=1;i*j<=n;j++)
         {
             f[i*j]+=i;
         }
    }
    for(i=1;i<=n;i++)
    {
        s[i]=s[i-1]+f[i];
    }
    int t,l,r;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&l,&r);
        printf("%I64d
",s[r]-s[l-1]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/cancangood/p/4563964.html