HDU 4342——History repeat itself——————【数学规律】
History repeat itself
This problem will be judged on HDU. Original ID: 4342
64-bit integer IO format: %I64d Java class name: Main
None
Graph Theory
2-SAT
Articulation/Bridge/Biconnected Component
Cycles/Topological Sorting/Strongly Connected Component
Shortest Path
Bellman Ford
Dijkstra/Floyd Warshall
Euler Trail/Circuit
Heavy-Light Decomposition
Minimum Spanning Tree
Stable Marriage Problem
Trees
Directed Minimum Spanning Tree
Flow/Matching
Graph Matching
Bipartite Matching
Hopcroft–Karp Bipartite Matching
Weighted Bipartite Matching/Hungarian Algorithm
Flow
Max Flow/Min Cut
Min Cost Max Flow
DFS-like
Backtracking with Pruning/Branch and Bound
Basic Recursion
IDA* Search
Parsing/Grammar
Breadth First Search/Depth First Search
Advanced Search Techniques
Binary Search/Bisection
Ternary Search
Geometry
Basic Geometry
Computational Geometry
Convex Hull
Pick's Theorem
Game Theory
Green Hackenbush/Colon Principle/Fusion Principle
Nim
Sprague-Grundy Number
Matrix
Gaussian Elimination
Matrix Exponentiation
Data Structures
Basic Data Structures
Binary Indexed Tree
Binary Search Tree
Hashing
Orthogonal Range Search
Range Minimum Query/Lowest Common Ancestor
Segment Tree/Interval Tree
Trie Tree
Sorting
Disjoint Set
String
Aho Corasick
Knuth-Morris-Pratt
Suffix Array/Suffix Tree
Math
Basic Math
Big Integer Arithmetic
Number Theory
Chinese Remainder Theorem
Extended Euclid
Inclusion/Exclusion
Modular Arithmetic
Combinatorics
Group Theory/Burnside's lemma
Counting
Probability/Expected Value
Others
Tricky
Hardest
Unusual
Brute Force
Implementation
Constructive Algorithms
Two Pointer
Bitmask
Beginner
Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
Greedy
Divide and Conquer
Dynamic Programming
Tag it!
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
To simplified the problem , The N will be within 231 and more then 0.
Output
Sample Input
4
1
3
6
10
Sample Output
2 2
5 7
8 13
13 28
Source
#include<bits/stdc++.h>
using namespace std;
typedef __int64 INT;
INT dfs(INT c){
INT cc=(INT)sqrt(c);
if(cc==0){
return 0;
}
INT ret=(c-cc*cc+1)*cc;
return ret+dfs(cc*cc-1);
}
int main(){
int t;
INT n,m;
scanf("%d",&t);
while(t--){
scanf("%I64d",&n);
INT nn=(INT)sqrt(n);
m=n+nn;
INT mm=(INT)sqrt(m);
if(mm>nn) //这条件开始写错了
m++;
INT ans=dfs(m);
printf("%I64d %I64d\n",m,ans);
}
return 0;
}
思路2:数学推导。http://www.cnblogs.com/kuangbin/archive/2012/08/08/2628794.html
#include<bits/stdc++.h>
using namespace std;
typedef __int64 INT;
INT dfs(INT c){
INT cc=(INT)sqrt(c);
if(cc==0){
return 0;
}
INT ret=(c-cc*cc+1)*cc;
return ret+dfs(cc*cc-1);
}
int main(){
int t;
INT n,m;
scanf("%d",&t);
while(t--){
scanf("%I64d",&n);
INT mm=(INT)ceil((1+sqrt(1+4*n))/2)-1;
m=mm+n;
INT ans=dfs(m);
printf("%I64d %I64d\n",m,ans);
}
return 0;
}
HDU 4342——History repeat itself——————【数学规律】的更多相关文章
- hdu 4342 History repeat itself(数学题)
题目链接:hdu 4342 History repeat itself 题意: 让你找第a个非完全平方数m,并且求前m个数的开方向下取整的和. 题解: 第一个问题: 假设第a个非平方数是X,X前面有n ...
- 二分查找+数学 HDOJ 4342 History repeat itself
题目传送门 题意:计算从1开始到第n个非完全平方数的开方和 分析:设第n个非完全平方数的值为a,x * x < a < (x+1) * (x+1),而且易得(tmp = sqrt (a) ...
- 多校-HDU 5351 MZL's Border 数学规律
f[1] = 'b', f[2] = 'a', f[i] = f[i - 1] + f[i - 2] 斐波那契数列的字符串,给你n和m,前m位中,最长的前缀等于后缀的长度是多少.1≤n≤1000, 1 ...
- 2017ACM暑期多校联合训练 - Team 2 1011 HDU 6055 Regular polygon (数学规律)
题目链接 **Problem Description On a two-dimensional plane, give you n integer points. Your task is to fi ...
- HDU 4342History repeat itself 数学
C - History repeat itself Time Limit:1000MS Memory Limit:32768KB Description Tom took the D ...
- 2012 #5 History repeat itself
History repeat itself Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))
C. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- [wx]自然数学规律
有趣的数学规律 椭圆 双曲线 抛物线都叫圆锥曲线 它们跟圆锥有着怎样的关系? 他们都是圆锥与平面在不同姿势下交配的产物. 参考 椭圆 抛物线 小结 e: 离线率 P: 任意一点 F: 焦点 准线: 一 ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
随机推荐
- [转]Passing Managed Structures With Strings To Unmanaged Code Part 1
1. Introduction. 1.1 Managed structures that contain strings are a common sight. The trouble is that ...
- requireJS入门基础
参考 require.js详解 1.引用requireJS的html文件 <!DOCTYPE html> <head> <title>requireJS</ ...
- html5 canvas绘制矩形和圆形
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- ubuntu - 14.04,安装JDK1.8(JAVA程序需要的开发、运行环境)
一,如何删除低版本的open JDK? 在ubuntn的软件中心中,如果输入"java",我们会看到open JDK,但是最高版本是1.7,也有1.6版本的,如果我们安装上去,可能 ...
- E - 稳定排序(结构体)
大家都知道,快速排序是不稳定的排序方法. 如果对于数组中出现的任意a[i],a[j](i<j),其中a[i]==a[j],在进行排序以后a[i]一定出现在a[j]之前,则认为该排序是稳定的. 某 ...
- vue 路由里面的 hash 和 history
对于 Vue 这类渐进式前端开发框架,为了构建 SPA(单页面应用),需要引入前端路由系统,这也就是 Vue-Router 存在的意义.前端路由的核心,就在于 —— 改变视图的同时不会向后端发出请求. ...
- [SinGuLaRiTy] 2017-07-21 综合性测试
[SinGuLaRiTy-1028] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 对于所有题目:Time Limit: 1s | Memo ...
- PHP 符号
注解符号: // 单行注解 /* */ 多行注解 引号的使用 ’ ’ 单引号,没有任何意义,不经任何处理直接拿过来; " "双引号,PHP动态处理然后输出,一般 ...
- 18.Jewels and Stones(珠宝和石头)
Level: Easy 题目描述: You're given strings J representing the types of stones that are jewels, and Sre ...
- react 中文文档案例四 (登陆登出按钮)
import React from 'react'; import ReactDOM from 'react-dom'; class LoginControl extends React.Compon ...