C - History repeat itself

Time Limit:1000MS     Memory Limit:32768KB     

Description

Tom took the Discrete Mathematics course in the 2011,but his bad attendance angered Professor Lee who is in charge of the course. Therefore, Professor Lee decided to let Tom face a hard probability problem, and announced that if he fail to slove the problem there would be no way for Tom to pass the final exam. 
As a result , Tom passed. 
History repeat itself. You, the bad boy, also angered the Professor Lee when September Ends. You have to faced the problem too. 
The problem comes that You must find the N-th positive non-square number M and printed it. And that's for normal bad student, such as Tom. But the real bad student has to calculate the formula below. 

So, that you can really understand WHAT A BAD STUDENT YOU ARE!!
 

Input

There is a number (T)in the first line , tell you the number of test cases below. For the next T lines, there is just one number on the each line which tell you the N of the case. 
To simplified the problem , The N will be within 2 31 and more then 0.
 

Output

For each test case, print the N-th non square number and the result of the formula.
 

Sample Input

4
1
3
6
10
 

Sample Output

2 2
5 7
8 13
13 28
 
题意:
  求第n个非平方数,
   求前n个数的sqrt(i)和
题解:
   求第n个非平方数,假设为y,y之前有x个平方数,则y=n+x,且sqrt(n+x)=x,可以得出y
   求前n个数的sqrt(i)和: 分段求就好了
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
typedef long long ll;
using namespace std;
#define inf 10000000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//***************************************************************
int main()
{
int t;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
ll n=read();
ll tmp=(ll)sqrt(n*1.0);
ll i=;
while((ll)sqrt(n+i)!=i)i++;
ll x=n+i;
ll flag=sqrt(n+i);
ll ans=;
for(ll i=;i<=flag;i++)
{
ans+=(i*i-(i-)*(i-))*(i-);
}
ans+=(x-flag*flag+)*flag;
cout<<x<<" "<<ans<<endl;
}
}
return ;
}

代码狗

 
 

HDU 4342History repeat itself 数学的更多相关文章

  1. HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spheric ...

  2. HDU 5584 LCM Walk 数学

    LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 ...

  3. HDU 4336 Card Collector 数学期望(容斥原理)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...

  4. HDU 5570 balls 期望 数学

    balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5570 De ...

  5. hdu 4710 Balls Rearrangement (数学思维)

    意甲冠军:那是,  从数0-n小球进入相应的i%a箱号.然后买一个新的盒子. 今天的总合伙人b一个盒子,Bob试图把球i%b箱号. 求复位的最小成本. 每次移动的花费为y - x ,即移动前后盒子编号 ...

  6. HDU 4790 Just Random 数学

    链接:pid=4790">http://acm.hdu.edu.cn/showproblem.php?pid=4790 意:从[a.b]中随机找出一个数字x,从[c.d]中随机找出一个 ...

  7. HDU 1018-Big Number(数学)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  8. HDU 1840 Equations (简单数学 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 ——每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2 ...

  9. HDU 5985 Lucky Coins 数学

    Lucky Coins 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5985 Description Bob has collected a lot ...

随机推荐

  1. swift中文文档- 类型转换

    未翻译完 待续(英语烂,求斧正) Type Casting 类型转换 Type casting is a way to check the type of an instance, and/or to ...

  2. Source Insight 基本使用(1)-使用Source Insight查看Android Framework 源码

    一.下载framework源码: google已经把framework源码托管在了gitHub上: https://github.com/android/platform_frameworks_bas ...

  3. C语言strchr()函数:查找某字符在字符串中首次出现的位置

    头文件:#include <string.h> strchr() 用来查找某字符在字符串中首次出现的位置,其原型为:    char * strchr (const char *str, ...

  4. Nginx HA 及https配置部署

    Nginx HA 整体方案架构为: (内网192.168.199.5) +-----------VIP----------+ | | | | Master Backup 192.168.199.90 ...

  5. iOS工程如何支持64-bit(转)

    苹果在2014年10月20号发布了一条消息:从明年的二月一号开始,提交到App Store的应用必须支持64-bit.详细消息地址为:https://developer.apple.com/news/ ...

  6. thinkphp中page方法

    page方法也是模型的连贯操作方法之一,是完全为分页查询而诞生的一个人性化操作方法. 用法 我们在前面已经了解了关于limit方法用于分页查询的情况,而page方法则是更人性化的进行分页查询的方法,例 ...

  7. wap版百度hi给你飞速的赶脚 赶紧登陆手机百度hi吧

    百度hi自然是百度自己的产品,如果你是做国内市场,这个产品应该要用一下.经常逛百度空间,有时实在受不了它的加载速度,(当然,这个跟你的网速.电脑配置.你所使用的百度空间模板等因素有关),我们看看百度空 ...

  8. 在link的url里新增参数

    (文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) <%= link_to image_tag("/images/icons/aaa. ...

  9. Windows Server 2012 GUI与Core的切换

    Server Core是在Windows Server 2008 系统上开始引入的极小的服务器安装选项,server core 的作用就是为特定的服务提供一个可执行的功能有限的低维护服务器环境,为我们 ...

  10. jekyll中文乱码问题

    一般编写都是采用utf-8的吧,但是在windows下安装的jekyll,默认是以GBK编码的方式去读取咱们编写的文件,如此便乱码了. 要解决此问题,总不至于要写GBK编码的文件吧,毕竟这个编码不怎么 ...