2012 #5 History repeat itself

History repeat itself

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 4342

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

 1 #include <stdio.h>
 2 #include <string.h>
 3
 4 long long a[70007],b[70007];
 5 int main()
 6 {
 7     int T;
 8     long long i,j,k;
 9     long long  n;
10     scanf("%d",&T);
11     a[0]=0;
12     for(i=1;i<=70000;i++)
13     {
14         a[i]=a[i-1]+i*(i*2+1);
15     }
16     for(i=1;i<=70000;i++)
17     {
18         b[i]=i*i-i+1;
19     }
20     while(T--)
21     {
22         scanf("%I64d",&n);
23         for(i=1;i<=70000;i++)
24         {
25             if(n<b[i])
26             {
27                 i--;
28                 break;
29             }
30         }
31         long long x=(n-b[i]+1)+i*i,y=a[i-1]+i*(n-b[i]+2);
32         printf("%I64d %I64d\n",x,y);
33     }
34     return 0;
35 }

时间: 2024-11-12 13:35:35

2012 #5 History repeat itself的相关文章

HDU 4342——History repeat itself——————【数学规律】

History repeat itself Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 434264-bit integer IO format: %I64d      Java class name: Main Prev Submit Status Statistics Discuss Next Type: None None Graph Theory 2-S

二分查找+数学 HDOJ 4342 History repeat itself

题目传送门 题意:计算从1开始到第n个非完全平方数的开方和 分析:设第n个非完全平方数的值为a,x * x < a < (x+1) * (x+1),而且易得(tmp = sqrt (a) ) == x,a之前的非完全平方数的个数为a - tmp,所以可以二分查找a - tmp == n的a,然后模拟一下能计算出前a个数的开方和 收获:二分查找是个好方法 代码: /************************************************ * Author :Running

HDU4342 History repeat itself数学规律题

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4342 题意: 就是要求第a个非平方数是什么 分析: 假设第a个非平方数是x,x前面有n个平方数,则n*n<x<(n+1)*(n+1); n*n前面的非平方数的个数是n*n-n; 首先先根据a求n,n是满足不等式  n*n-n<a的最大正整数. 不等式的解是: (1+sqrt(1+4*a))/2;必需对这个数上取整,然后减一就是n了. 然后第a个非平方数就是  n*n+(a-n*n+n)=a

HDU 4342History repeat itself 数学

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

HDU-4464-Browsing History (2012 ACM/ICPC成都现场赛!)

Browsing History Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3065    Accepted Submission(s): 1692 Problem Description One day when you are going to clear all your browsing history, you come

Windows server 2012 AD架构 试验 系列22 -ADAC与PowerShell History

Windows server 2012 AD架构 试验 系列22 -ADAC与PowerShell History ADAC是建立于Windows PowerShell之上的一个用户界面工具.在WindowsServer2012,IT管理员可以利用ADAC中的WindowsPowerShell记录查看器来学习Windows PowerShell.最终目的是使得管理员可以创建自动化脚本和减少重复工作,从而提高IT生产力.操作很简单且直观. 比如把administrator加入到domain gue

Deep Learning in a Nutshell: History and Training

Deep Learning in a Nutshell: History and Training This series of blog posts aims to provide an intuitive and gentle introduction to deep learning that does not rely heavily on math or theoretical constructs. The first part in this series provided an

使用ajax和history.pushState无刷新改变页面URL

表现 如果你使用chrome或者firefox等浏览器访问本博客.github.com.plus.google.com等网站时,细心的你会发现页面之间的点击是通过ajax异步请求的,同时页面的URL发生了了改变.并且能够很好的支持浏览器前进和后退. 是什么有这么强大的功能呢? HTML5里引用了新的API,history.pushState和history.replaceState,就是通过这个接口做到无刷新改变页面URL的. 与传统的AJAX的区别 传统的ajax有如下的问题: 1.可以无刷新

HDU 4464 Browsing History(最大ASCII的和)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4464 Problem Description One day when you are going to clear all your browsing history, you come up with an idea: You want to figure out what your most valued site is. Every site is given a value which e