hdu_4342 History repeat itself (简单想法题)
来源:互联网 发布:关口知宏评价中国 编辑:程序博客网 时间:2024/06/05 03:52
http://acm.hdu.edu.cn/showproblem.php?pid=4342
题意:
求出第n个非平方数,并根据公式求出结果。
思路:
简单题。先求出第n个非平方数是多少,再代入公式计算。计算我是用i*(i+1)^2-i^2)再求和算的,纸上画画,很容易得出这个结论。
我的代码:
#include<stdio.h>#include<math.h>__int64 x[100001],i,j,n,t,T;__int64 formula(__int64 m){ __int64 ans=0,i,j,n; n=(__int64)sqrt(m*1.0); for(i=1;i<n;i++) ans+=(x[i+1]-x[i])*i; ans+=(m-x[i]+1)*i; return ans;}int main(){ for(i=0;i<100000;i++) x[i]=i*i; scanf("%I64d",&T); while(T--) { scanf("%I64d",&n); t=(__int64)sqrt(n*1.0); n+=t;//看n前面有多少个平方数 if(n>=x[t+1]) n++;//超过了t+1个平方数 printf("%I64d %I64d\n",n,formula(n)); } return 0;}
- hdu_4342 History repeat itself (简单想法题)
- HDU 4342 History repeat itself 简单公式
- hdu 4342 History repeat itself 模拟题
- HDU4342 History repeat itself数学规律题
- hdu 4342 History repeat itself(思维)
- HDU4342 History repeat itself
- History repeat itself 解题
- hdu 4342 History repeat itself
- HDU 4342 History repeat itself
- HDOJ 4342 History repeat itself
- HDU 4342 History repeat itself
- HDU 4342 - History repeat itself
- HDOJ 4342 History repeat itself
- hdu - 4342 - History repeat itself - 纯数学水题
- HDU4342——History repeat itself(数学)
- HDU 4342 History repeat itself 模拟
- HDU 4342 ——History repeat itself
- 【杂题】 HDOJ 4342 History repeat itself
- 有用的:nth-child秘方
- Oracle数据库监听配置
- poj1947(树形dp)
- Java 深拷贝
- NPOI 生成Excel 的——常用
- hdu_4342 History repeat itself (简单想法题)
- 最近半年计划
- 黑马程序员——内部类
- java正则表达式
- Android Intent Flag的介绍
- 图像平滑-邻域平均法
- 如何理解软件开发规范性与灵活性
- 使用Oracle SQLDeveloper连接数据库并创建用户
- 在IE中使用first-child和last-child [半原][旧]