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 |
| Sample Output |
17 |
| 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)的更多相关文章
- hnnu 11546 Sum of f(x) (求一个数的全部约数和)
代码: #include<cstdio> #include<cstring> #define N 200000 using namespace std; long long f ...
- hunnu Sum of f(x)
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11546&courseid=0 Sum of f(x) ...
- 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) + ...
- 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 ...
- hdu 4389 X mod f(x) 数位DP
思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...
- 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 ...
- poj 1564 Sum It Up (DFS+ 去重+排序)
http://poj.org/problem?id=1564 该题运用DFS但是要注意去重,不能输出重复的答案 两种去重方式代码中有标出 第一种if(a[i]!=a[i-1])意思是如果这个数a[i] ...
- 牛客练习赛19 E和F(签到就走系列)托米的饮料+托米搭积木
E题传送门:点我 F题传送门:点我 可爱的小托米得到了n瓶饮料. 但他不小心把开盖的工具弄丢了,所以他只能利用饮料瓶来开盖. 已知第i个瓶子的品牌为ai,且其能打开bi品牌的瓶子. 问有几瓶饮料托米无 ...
- 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号结 ...
随机推荐
- 浅析java的浅拷贝和深拷贝
Java中任何实现了Cloneable接口的类都可以通过调用clone()方法来复制一份自身然后传给调用者.一般而言,clone()方法满足: (1) 对任何的对象x,都有x.clone( ...
- 用 managedQuery() 时须要注意的一个陷阱
Activity 里面提供了一个 managedQuery() 方法,依照 Android SDK 里面的说明,"the activity will manage its lifecycle ...
- C++ - Operator Precedence
The following table lists the precedence and associativity of C++ operators. Operators are listed to ...
- objective-c 中数据类型之中的一个 几何数据类型(CGPoint,CGSize,CGRect)
// CGPoint 结构体数据原型, 用于声明一个点: /* Points. */ struct CGPoint { CGFloat x; CGFloat y; }; typedef struct ...
- 一段代码让你秒懂java方法究竟是传值还是传地址
先看看代码以及执行结果: 凝视写得非常清楚了.我就不多说了. 我说说我的结论.事实上在java中没有传值还是传址的概念,java仅仅有引用的概念.引用类似传址.只是是一个变量名中保存着对象的地址,地址 ...
- Web Api集成Swagger
WebApi集成Swagger 1.新建一个WebApi空项目 2.新建一个Person实体类: public class Person { public int ID { get; set; } p ...
- Java NIO 完全学习笔记(转)
本篇博客依照 Java NIO Tutorial翻译,算是学习 Java NIO 的一个读书笔记.建议大家可以去阅读原文,相信你肯定会受益良多. 1. Java NIO Tutorial Java N ...
- 深入 CSocket 编程之阻塞和非阻塞模式
有时,花上几个小时阅读.调试.跟踪优秀的源码程序,能够更快地掌握某些技术关键点和精髓.当然,前提是对这些技术大致上有一个了解. 我通过几个采用 CSocket 类编写并基于 Client/Server ...
- Storyboard 经常用法总结-精华版
1.prepareForSegue: Now we know what the destinationViewController is we can set its data properties. ...
- JavaScript 中的事件流和事件处理程序(读书笔记思维导图)
JavaScript 程序采用了异步事件驱动编程模型.在这种程序设计风格下,当文档.浏览器.元素或与之相关的对象发生某些有趣的事情时,Web 浏览器就会产生事件(event). JavaScript ...