hunnu11546:Sum of f(x)
来源:互联网 发布:淘宝实名认证用银行卡 编辑:程序博客网 时间:2024/05/01 02:40
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
超时,改成
才AC
Input 第一行为一个整数T(T<=100000),表示数据的组数。
接下来T行,每行有两个整数l,r(1 <= l <= r <= 200000)
Output 对每组数据,输出f(l)+f(l+1)+……+f(r) 的和
Sample Input
23 510 20Sample Output
17270Problem Source HUNNU Contest
开始用这种方法来求
for(i = 3; i<=200000; i++) { a[i] = 1+i; for(j = 2; j*j<=i; j++) { if(i%j==0) { a[i]+=j; if(i/j!=j) a[i]+=(i/j); } } }
超时,改成
for(i = 1; i<=200000; i++) { for(j = 1; i*j<=200000; j++) { a[i*j]+=i; } }
才AC
开了一个变量去级数,发现上面的运算了5千多W次
下面的才两百多W次
看来差别还是蛮大的
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <bitset>#include <algorithm>#include <climits>#include <time.h>using namespace std;#define LS 2*i#define RS 2*i+1#define UP(i,x,y) for(i=x;i<=y;i++)#define DOWN(i,x,y) for(i=x;i>=y;i--)#define MEM(a,x) memset(a,x,sizeof(a))#define W(a) while(a)#define gcd(a,b) __gcd(a,b)#define LL long long#define N 200005#define MOD 1000000007#define INF 0x3f3f3f3f#define EXP 1e-8LL a[N];LL sum[N];void init(){ LL i,j,k; MEM(a,0); MEM(sum,0); for(i = 1; i<=200000; i++) { for(j = 1; i*j<=200000; j++) { a[i*j]+=i; } } for(i = 1; i<=200000; i++) sum[i] = sum[i-1]+a[i];}int main(){ LL i,j,k; int l,r; init(); int t; scanf("%d",&t); while(t--) { scanf("%d%d",&l,&r); printf("%I64d\n",sum[r]-sum[l-1]); } return 0;}
0 0
- hunnu11546:Sum of f(x)
- hunnu-11546--Sum of f(x)
- HUNNU 11546 Sum of f(x)
- NBUT The Sum of F(x) and G(x)
- NBUT 1555 The Sum of F(x) and G(x)
- [noj 1555] The Sum of F(x) and G(x)
- [数学]Sum of f(x) 约数之和问题
- hnnu 11546 Sum of f(x) (求一个数的所有约数和)
- F[x]
- F(x)
- F(X)
- F(X)
- F(x)
- F(x)
- POJ 1060/ ZOJ 1026 : Modular Multiplication of Polynomials - f(x)g(x) mod h(x)
- HDU 3415 Max Sum of Max-X-sub-sequence
- cf#ECR7 - F - The Sum of the k-th Powers -拉格朗日插值/逆元/数学
- Codeforces Educational Codeforces Round 7 - F. The Sum of the k-th Powers
- 【Linux 1.0内核源码剖析】执行程序——exec.c
- android中解析doc、docx、xls、xlsx格式文件
- 进一步提升高速穷尽哈密顿回路的方法
- 线程假唤醒现象
- #!的写法
- hunnu11546:Sum of f(x)
- 初识计算机系统
- 集成Qt5.2到VS 2013
- 使用代码在布局中创建控件
- wait()+notify实现java生产者-消费者
- 为什么国外程序员爱用 Mac
- js数组
- cordic算法原理及verilog实现
- 使用dbutils时insert语句报错