History repeat itself 解题
来源:互联网 发布:unity 软件位置 编辑:程序博客网 时间:2024/05/23 01:13
【题目描述】
Description
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 231 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.求第n个非平方数是多少?
此处证明略,稍后补充。
2.求题目中表达式
对1~n的值求
第
则
对于每一个
设
则有
这些项的和为:
(
再加从
所以总和为
【代码】
#include<stdio.h>#include<math.h>int main() { int t; scanf("%d", &t); while (t--) { long long int n, m, a; scanf("%lld", &n); long long int sum = 0; n = n + sqrt(n * 1.0) + 0.5; m = sqrt(n * 1.0); a = m - 1; sum = (a * (a + 1) * (2 * a + 1)) / 3 + (a * (a + 1)) / 2 + (n - m * m + 1) * m; printf("%lld %lld\n", n, sum); } return 0;}
- History repeat itself 解题
- HDU4342 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 模拟
- hdu 4342 History repeat itself 模拟题
- HDU 4342 ——History repeat itself
- 【杂题】 HDOJ 4342 History repeat itself
- HDU4342 History repeat itself数学规律题
- HDU 4342 History repeat itself 简单公式
- HDOJ 4342History repeat itself(数学)
- hdu 4342 History repeat itself(思维)
- hdu4342 History repeat itself-------多校联合五
- 2012 Multi-University Training Contest 5:History repeat itself
- 猜数字游戏
- Python3 open()函数
- N76E003 在Keil下载出现 *** Error: Flash Verify Failed at 0x0000
- 1087 1 10 100 1000
- 结合redis设计与实现的redis源码学习-23-排序(sort.c)
- History repeat itself 解题
- 项目管理2
- 计算输入的数字的平均数,并输出大于平均数的数字
- jsp图书管理系统(2048)
- python同时安装2.x版本和3.x版本
- 关于线程同步(7种同步方式)
- java8学习总结——Collector接口
- jsp图书管理系统(版本一)
- Mysql-5.7二进制免编译安装