京东笔试第一题,序列


/**
* 求1 2 2 3 3 3 4 4 4 4 5 5 5 5 5.... 第k项数是多少。
* 通过
*/
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
double n = Double.parseDouble(scanner.nextLine());
if (n <= 0) {
System.out.println(0);
return;
}
if (n > Math.pow(10, 18)) {
System.out.println(0);
return;
}
double x = Math.sqrt(1 + 8 * n);
double y = (x - 1) / 2;
System.out.println((int) (Math.ceil(y)));
}


#京东#
全部评论
int main(int argc, char **argv) { int n; while (cin >> n) { cout << (unsigned long long)(sqrt((double)2 * n) + 0.5) << endl; } //cin.get(); return 0; }
点赞 回复 分享
发布于 2017-09-08 22:07
我是这么做的,考场上忘记i = int(i)了,一直80%,不知道现在改的对不对~ import math import sys n = int(sys.stdin.readline().strip()) i = math.sqrt(2*n) i = int(i) if i*(i+1) < 2*n: i+=1 print(int(i))
点赞 回复 分享
发布于 2017-09-08 22:02
这个题是把长度转为等差数列计算 import sys x = int(sys.stdin.readline().strip()) i = int((2*x)**0.5-0.5)+1 print i
点赞 回复 分享
发布于 2017-09-08 21:55

相关推荐

我面试,她问我有女朋友没
不甜主义:考验稳定性,单身牛马更注意力集中
点赞 评论 收藏
分享
大佬们,在大厂实习的都是几百一天???
哈尔滨的移动城堡_:那几个有名的大厂都是300-400,小厂有更高的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务