zoj 3175 Number of Containers(数论~)
2011-01-23 18:38
387 查看
算是数论吧。 = =
就是求i从1到n的 n/i-1的累和。
开始我用最简单的累和,算20Y要好几秒,肯定过不去,也想了到n的平方根,思路是对的,可是没想明白 = =就去看别人题解了,破习惯。
结果人家就是用的到n的平方根 = =。。让姐情何以堪。。。
看懂了。大家画个函数图,y = n/x,以 y = x对称,下面的部分计算的时候,上半部分y-根号n为下面曲线上点的纵坐标。。。下面也有根号n个点,所以总共减去根号n*根号n。
就是求i从1到n的 n/i-1的累和。
开始我用最简单的累和,算20Y要好几秒,肯定过不去,也想了到n的平方根,思路是对的,可是没想明白 = =就去看别人题解了,破习惯。
结果人家就是用的到n的平方根 = =。。让姐情何以堪。。。
看懂了。大家画个函数图,y = n/x,以 y = x对称,下面的部分计算的时候,上半部分y-根号n为下面曲线上点的纵坐标。。。下面也有根号n个点,所以总共减去根号n*根号n。
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> #include <math.h> using namespace std; int main() { int ncases,i,n; long long ans; scanf("%d",&ncases); while( ncases-- ) { ans = 0; scanf("%d",&n); for(i=1; i<=sqrt(n); i++) ans += (n/i); ans *= 2; i--; ans = ans - i*i - n; printf("%lld/n",ans); } return 0; }
相关文章推荐
- TOJ 2909 ZOJ 3175 Number of Containers / 数论
- ZOJ 3175 Number of Containers(n/1+n/2+...+n/(n-1)+n/n求法)
- ZOJ - 3175 Number of Containers
- zoj 3175 Number of Containers (nbut1375) 计算n /1+n/2+n/3+n/4....+n/n
- zoj 3175 Number of Containers 分块加速
- ZOJ 2523 —— Number of People(数论,胡搞)
- zoj 3175 Number of Containers (大数灵活题,除2改成平方根)
- ZOJ 3175 Number of Containers 【数学图像性质(一个常见算式的经典计算)】
- zoj 3175 Number of Containers
- HDU 1492 The number of divisors(约数) about Humble Numbers(数论题目要知道定理呀....)
- codeforces 27E E. Number With The Given Amount Of Divisors(dp+数论)
- [zoj 3774]Power of Fibonacci 数论(二次剩余 拓展欧几里得 等比数列求和)
- [zoj 3774]Power of Fibonacci 数论(二次剩余 拓展欧几里得 等比数列求和)
- ZOJ 3449 Doraemon's Number Game III (数论)
- Ccodeforces 27E Number With The Given Amount Of Divisors(数论+搜索)
- 数论之神 god of number theory
- ZOJ 1484 Minimum Inversion Number(线段树,数论)
- HDU1492-The number of divisors(约数) about Humble Numbers-数论(计数问题)
- codeforces 27E - Number With The Given Amount Of Divisors (数论 dfs)
- Number of Containers(数学)