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. JavaScript实现全排列

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> ...

  2. 实现JavaScript自定义函数的整合、链式调用及类的封装

    函数声明形式:表单验证函数 1 2 3 4 5 6 7 8 9 10 11 12 13 function checkName(){     console.log('检查用户名'); } functi ...

  3. kindle paperwhite折腾记

    在亚马逊官网上买了一个kindle paperwhite 一代(849元) , 打算再买个皮套, 淘宝店  http://detail.tmall.com/item.htm?spm=a230r.1.1 ...

  4. iOS开发之#iPhone6与iPhone6Plus适配#Xcode6.0/Xcode6.1上传应用过程中一些变动以及#解决方案#

    更新时间2014年11月13日  本博文创建时,只有Xcode6.0, Xcode6.0尝试多次,确实如此 之后在6.1版本经博主少量尝试,确实也有如下问题,现更新下博客! iOS8发布之后,苹果强制 ...

  5. Entity Framework在SaveChanges()之前拿到对象的自增长ID

    现有两张表A.B在一个dbContext中更新,且A表的ID为B的外键, Insert(A); B.aid=A.ID; Insert(B); SaveChanges() 按照这个顺序就可以了满足要求, ...

  6. 小白科普之JavaScript的BOM模型

    一.什么是BOM 1. BOM是browser object model的缩写,简称浏览器对象模型: 2. BOM提供了独立于内容而与浏览器窗口进行交互的对象,描述了与浏览器进行交互的方法和接口: 3 ...

  7. NGUI之scroll view制作,以及踩的坑总结

    http://blog.csdn.net/monzart7an/article/details/23878505 链接: http://game.ceeger.com/forum/read.php?t ...

  8. puppet组织架构

    树结构如下: |-- puppet.conf #主配置配置文件 |-- fileserver.conf #文件服务器配置文件 |-- auth.conf #认证配置文件 |-- autosign.co ...

  9. java前三本基础知识总结

    基础软件:1:JDK,JRE,JVM(一些参数和作用),GC(机制和算法),Class,Loader(机种作用,加载顺序) 2:环境搭建:JAVA_HOME,path,class 语言基础:引用类型: ...

  10. 【SpringMVC】SpringMVC系列4之@RequestParam 映射请求参数值

    4.@RequestParam 映射请求参数值 4.1.概述     Spring MVC 通过分析处理方法的签名,将 HTTP 请求信息绑定到处理方法的相应人参中.Spring MVC 对控制器处理 ...