HDOJ 4342 History repeat itself
来源:互联网 发布:泽东书法 知乎 编辑:程序博客网 时间:2024/05/22 15:38
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4342
一道简单的数论题……其实说这道题是数论有点牵强,因为这道题并没有用到特别费脑的数学规律。
题意是让我们求第a个非平方数,以及1~a的所有的开根的和。
先说求第a个非平方数。设离a最近的那个平方数为n^2,那么显然,在n^2之前有n^2-n个非平方数,首先,我们把这个n解出来,也就是解出n*n-n < a这个不等式成立的最大的n,解得n < sqrt(a+1/4)+1/2,得到满足的最大的n之后我们再来求解第二个问,这个很好思考,在n^2~(n+1)^2之间的数,开根得到的都是n,所以我们能够很容易的得到答案。
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;int main(){int T;scanf("%d", &T);while(T--){LL a;cin >> a;double tmp = ceil((1+sqrt(1+4*a))/2)-1;LL n = (LL)tmp;LL res1 = a+n;LL res2 = n*(n+1)*(2*n+1)/3 - 3*(n+1)*n/2 + n + (n+a-n*n+1)*n;printf("%I64d %I64d\n", res1, res2);}return 0;}
0 0
- HDOJ 4342 History repeat itself
- HDOJ 4342 History repeat itself
- 【杂题】 HDOJ 4342 History repeat itself
- HDOJ 4342History repeat itself(数学)
- hdu 4342 History repeat itself
- HDU 4342 History repeat itself
- HDU 4342 History repeat itself
- HDU 4342 - History repeat itself
- HDU 4342 History repeat itself 模拟
- hdu 4342 History repeat itself 模拟题
- HDU 4342 ——History repeat itself
- HDU 4342 History repeat itself 简单公式
- hdu 4342 History repeat itself(思维)
- HDU4342 History repeat itself
- History repeat itself 解题
- hdu - 4342 - History repeat itself - 纯数学水题
- HDU4342 History repeat itself数学规律题
- HDU 4342 History repeat itself 2012 Multi-University Training Contest 5
- 【VS开发】修改MainFrame窗口名称1
- android 电源管理介绍
- UVA 11029 Leading and Trailing [数学]
- [LeetCode]Delete Digits
- (转)C++ 字符串类型转换为其他字符串
- HDOJ 4342 History repeat itself
- JSP中include指令和include动作浅析
- 文本框禁止浏览器缓存
- 如何编写异常安全的C++代码
- pl/sql变量类型
- 示波器入门之采样率、存储深度
- Android资源文件中各种XML的作用与解释
- 【VS开发】设置文档标题
- 解读VC++编程中的文件操作API和CFile类