CF622A.Infinite Sequence
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the n-th position of the sequence.
考虑以下无穷整数序列:1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5... 该序列按如下方式构造:首先写出数字 1,然后写出从 1 到 2 的所有数字,接着写出从 1 到 3 的所有数字,再写出从 1 到 4 的所有数字,依此类推。注意,该序列中包含的是数字,而非数字的各位数码。例如,数字 10 首次出现在序列的第 55 个位置(序列元素从 1 开始编号)。
求该序列中第 n 个位置上的数字。
输入格式
The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
唯一的一行包含一个整数 n(1≤n≤1014)——即要查找的数字的位置。
注意,给定的数字非常大,因此你应使用 64 位整数类型来存储它。在 C++ 中可以使用 long long 整数类型,在 Java 中可以使用 long 整数类型。
输出格式
Print the element in the n-th position of the sequence (the elements are numerated from one).
输出序列中第 n 个位置的元素(元素编号从 1 开始)。
输入输出样例
输入#1
3
输出#1
2
输入#2
5
输出#2
2
输入#3
10
输出#3
4
输入#4
55
输出#4
10
输入#5
56
输出#5
1
输入解题思路,AI测评打分。不知道怎么写?