Divisor Summation_
2016-02-17 19:27
459 查看
Divisor Summation
Problem Description
Give a natural number n (1 <= n <= 500000), please tell the summation of all its proper divisors. Definition: A proper divisor of a natural number is the divisor that is strictly less than the number.e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor summation is: 1 + 2 + 4 + 5 + 10 = 22.
Input
An integer stating the number of test cases, and that many lines follow each containing one integer between 1 and 500000.Output
One integer each line: the divisor summation of the integer given respectively.Sample Input
32
10
20
###Sample Output
1
8
22
参考代码
int sum[500001]; int main() { int n, a; sum[1] = 0; for (int k = 2; k <= 500000; k++) sum[k] = 1; for (int i = 2; i <=250000; i++) { for (int j = 2; j <= 500000/i; j++) sum[j*i] += i; } //freopen("d:\\out.txt", "w", stdout); while (scanf("%d", &n) != EOF) { for (int i = 0; i < n;i++)//坑啊 改了两次竟然没发现少写了个循环 一定要细心 { scanf("%d", &a); printf("%d\n", sum[a]); } } //system("pause"); }
如果用一般的暴力解法的话会超时,用打表法反而更快
相关文章推荐
- matlab坐标轴axes对象句柄消失的解决办法
- 进程和线程的区别与联系是什么?
- POJ 3279反转问题,dp
- iOS中UITextView的字数限制
- 为什么会出现数据安全问题?资源抢夺有哪些解决办法
- 查询oracle表的信息(表,字段,约束,索引)
- 必须掌握的八种排序(5-6)--冒泡排序,快速排序
- 对UIView、UIWindow和CALayer的理解
- 九度[1120]全排列
- PHP的异常处理机制
- Unity全景项目经验Q&A
- Pch文件的主要作用 和分类Category的作用
- XML解析
- Linux 系统 常用 命令学习(1)
- 那些上传AppStore遇到的坑
- ASP.Net MVC利用NPOI导入导出Excel - RuleLu
- http 的post与get区别与联系,实践中怎么选择
- String
- 近期博客计划清单
- [题解][NOI2015]软件包管理器