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;
}

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

  1. hnnu 11546 Sum of f(x) (求一个数的全部约数和)

    代码: #include<cstdio> #include<cstring> #define N 200000 using namespace std; long long f ...

  2. hunnu Sum of f(x)

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11546&courseid=0 Sum of f(x) ...

  3. 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) + ...

  4. three Sum

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  5. hdu 4389 X mod f(x) 数位DP

    思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...

  6. geeksforgeeks@ 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 b ...

  7. poj 1564 Sum It Up (DFS+ 去重+排序)

    http://poj.org/problem?id=1564 该题运用DFS但是要注意去重,不能输出重复的答案 两种去重方式代码中有标出 第一种if(a[i]!=a[i-1])意思是如果这个数a[i] ...

  8. 牛客练习赛19 E和F(签到就走系列)托米的饮料+托米搭积木

    E题传送门:点我 F题传送门:点我 可爱的小托米得到了n瓶饮料. 但他不小心把开盖的工具弄丢了,所以他只能利用饮料瓶来开盖. 已知第i个瓶子的品牌为ai,且其能打开bi品牌的瓶子. 问有几瓶饮料托米无 ...

  9. Codeforces Round #530 (Div. 2):D. Sum in the tree (题解)

    D. Sum in the tree 题目链接:https://codeforces.com/contest/1099/problem/D 题意: 给出一棵树,以及每个点的si,这里的si代表从i号结 ...

随机推荐

  1. Android 环境变量配置(Mac)

    Mac 系统10.10,自带的就是jdk1.6,因为工作需要就升级到了1.7,要从新配置环境变量了 mac 默认是自带的有jdk1.6 安装路径为: /System/Library/Framework ...

  2. hdc和hwnd的区别

    句柄概念在WINDOWS编程中是一个很重要的概念,在许多地方都扮演着重要的角色.但由此而产生的句柄概念也大同小异,比如:<<Microsoft   Windows   3   Develo ...

  3. javascript中apply和eval结合的强大用法

        eval是一个函数,可以接受一个参数,这个参数可以作为js语句被解释性的执行,利用这个特性,eval和apply结合起来,可以大大简化代码  如下例子 <a class="cl ...

  4. org.springframework.core.Ordered接口

    关于Ordered接口,用过的人可能知道,这里我谈下自己的理解.也希望各位大神能给予指点. 源码如下: /**  * Interface that can be implemented by obje ...

  5. JS - 点击 “+” 、“-” 改变数字

    效果: 代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.a ...

  6. 外国的Delphi网站

    www.phidels.com delphifr.com http://www.swissdelphicenter.com/torry/showcode.php?id=787 B4A delphifa ...

  7. MySQL 採用Xtrabackup对数据库进行全库备份

    1,xtrabackup简单介绍 关于数据库备份以及备份工具.參考:http://blog.itpub.net/26230597/viewspace-1460065/,这里来介绍xtrabackup已 ...

  8. 链栈之C++实现

    链栈是借用单链表实现的栈.其不同于顺序栈之处在于: 1.链栈的空间是程序运行期间根据需要动态分配的,机器内存是它的上限.而顺序栈则是 静态分配内存的. 2.链栈动态分配内存的特性使得它一般无需考虑栈溢 ...

  9. SQLite/嵌入式数据库

    SQLite/嵌入式数据库 的项目要么不使用数据库(一两个文配置文件就可以搞定),要么就会有很多的数据,用到 postgresql,操练sqlite的还没有.现在我有个自己的小测试例子,写个数据库对比 ...

  10. html5实现拖拽文件上传

    以下是自学it网--中级班上课笔记 网址:www.zixue.it html文件 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict ...