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. spring mvc实现查询

    实体类:User package cn.bdqn.pojo; public class User { private String userName; private String password; ...

  2. ProcDump

    https://technet.microsoft.com/en-us/sysinternals/dd996900.aspx

  3. django静态文件查找逻辑

    最近被django的静态文件配置整疯了. 决定直捣黄龙,看看底层代码: 首先用manage finstatic xxxx.js 看看处理逻辑,发现主要在:C:\Python27\Lib\site-pa ...

  4. 【OpenStack】OpenStack系列13之Nova源码解析与API扩展

    学习思路 议程:代码结构-主干流程-分层架构-业务模型-数据库模型-消息模型 分布式架构:Api:横向扩展    rpc:纵向扩展 分层架构:Controller接口层.View/Manager逻辑层 ...

  5. 尖刀出鞘的display常用属性及css盒模型深入研究

    一:diplay:inline-block 含义:指元素创建了一个行级的块级元素,该元素内部(内容)被格式化成一个块级元素,同时元素本身则被格式化成一个行内元素.更简单的说就是说inline-bloc ...

  6. C# 支持多种语言

    通过Resource文件建立本地化. net 资源文件名(这里是Resource1.resx)由根名称(即Resource1),本地语言名称(默认情况下还没有)及扩展名组成,在读取资源时,资源管理器会 ...

  7. Office 2010启动时出现无法验证此应用程序的许可证的解决

    Office 2010启动之后弹出一个窗口提示:Microsoft Office无法验证此应用程序的许可证.修复尝试失败或者已被用户取消.应用程序将立即关闭. 遇到这样的情况,原因是Office的系统 ...

  8. CodeForces - 424B (贪心算法)

    Megacity Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

  9. July 23rd, Week 30th Saturday, 2016

    A day is a miniature of eternity. 一天是永恒的缩影. For a man, the eternity is his lifetime which is measure ...

  10. July 12th, Week 29th Tuesday, 2016

    When the traveler goes alone he gets acquainted with himself. 独自旅行可以让人更好地了解自己. With other's company, ...