hunnu-11546--Sum of f(x)

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;
}
时间: 2024-08-26 21:02:33

hunnu-11546--Sum of f(x)的相关文章

hnnu 11546 Sum of f(x) (求一个数的所有约数和)

代码: #include<cstdio> #include<cstring> #define N 200000 using namespace std; long long f[N+5]; long long s[N+5]; int main() { s[0]=0; for(int i=1;i<=N;i++) { for(int j=1;j*i<=N;j++) { f[j*i]+=i; } } for(int i=1;i<=N;i++) { s[i]=s[i-1]

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 Prob

NBUT The Sum of F(x) and G(x)

问题描述 When Deathmoon played MC game, he faced a math problem. When he found a ancient tomb and came in, he found two polynomials f(x) and g(x) no the wall, only did he calculate f(x) + g(x) correctly he could come in, can you help him? For example: f(

hunnu11546:Sum of f(x)

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

HDU 1003 Max Sum

题目: Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14. Input The first line of the input cont

[email&#160;protected] Find sum of different corresponding bits for all pairs (Bit manipulation)

http://www.practice.geeksforgeeks.org/problem-page.php?pid=387 Find sum of different corresponding bits for all pairs We define f (X, Y) as number of different corresponding bits in binary representation of X and Y. For example, f (2, 7) = 2, since b

BZOJ(begin) 1375 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队:dp【和为f的倍数】

题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1375 题意: 给你n个数,你可以从中选任意多个,但不能不选.问你所选数字之和为f的倍数的方案数. 题解: 表示状态: dp[i][j] = num of ways i:考虑到第i个数(还没选) j:之前所选数之和 MOD f == j 找出答案: ans = dp[n][0] - 1 不选也是一种方案,但题目种要求不能不选,所以-1. 如何转移: 选或不选第i个数. dp[i+1][

HDU 4734 F(x) (数位DP,基础)

题意:  一个非负整数的十进制位是这样的 (AnAn-1An-2 ... A2A1),定义F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1.给出A和B,问[0,B]中有几个整数x的F(x)值<=F(A)? 思路: 算一下就知道F(x)值不会超过512*9,而B仅仅有8位十进制数,那么8*512*9就可以算出所有的统计了.对于每个询问,先计算F(A)的值,然后统计小于此值有几个就行了.统计的复杂度也是很低的.若是以前缀和来统计后面的个数的

leetcoder-112-Path Sum

Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, 5 / 4 8 / / 11 13 4 / \ 7 2 1 return