CodeForces 622 A.Infinite Sequence
1 second
256 megabytes
standard input
standard output
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 10first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the n-th position of the sequence.
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 thelong long integer type and in Java you can use long integer type.
Print the element in the n-th position of the sequence (the elements are numerated from one).
3
2
5
2
10
4
55
10
56
1 数学题,找规律即可。
#include <iostream>
using namespace std;
typedef long long ll; int main()
{
ll n;
cin >> n;
for(int i = ; n > i; i++)
{
n-=i;
}
cout << n;
return ;
}
CodeForces 622 A.Infinite Sequence的更多相关文章
- codeforces 675A A. Infinite Sequence(水题)
题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...
- codeforces 622A A. Infinite Sequence (二分)
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【CodeForces 622A】Infinite Sequence
题意 一个序列是, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5....这样排的,求第n个是什么数字. 分析 第n个位置属于1到k,求出k,然后n-i*(i-1)/ ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- codeforces 622A Infinite Sequence
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- HZNU 2019 Summer training 6 -CodeForces - 622
A - Infinite Sequence CodeForces - 622A 题目大意:给你一个这样的数列1,1,2,1,2,3,1,2,3,4,1,2,3,4,5....就是从1~n排列(n++ ...
- 【arc071f】Infinite Sequence(动态规划)
[arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...
- Codeforces 486E LIS of Sequence(线段树+LIS)
题目链接:Codeforces 486E LIS of Sequence 题目大意:给定一个数组.如今要确定每一个位置上的数属于哪一种类型. 解题思路:先求出每一个位置选的情况下的最长LIS,由于開始 ...
随机推荐
- BZOJ 1507 Editor(块状链表)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1507 题意:一个文本编辑器,模拟以下操作: 思路:块状链表的主要操作: (1)find( ...
- Map和hash_map
map和hash_map 今天在写拼流的程序时碰到一个问题,要根据流的四元组的结构信息映射到该流的数据.也就是我在网络数据包拼接的过程中,要根据包的地址和端口信息,对应到其对应的一个流的数据上去,把端 ...
- oracle创建表空间、创建用户、授权、夺权、删除用户、删除表空间
表空间定义 表空间是为了统一ORACLE物理和逻辑上的结构而专门建立的,从物理上来说,一个表空间是由具体的一个或多个磁盘上数据文件构成的(至少1对1,可以1对多),从逻辑上来说一个表空间是由具体的一个 ...
- JS生成指定长度的随机数
/** * 生成指定长度的UUID * @param len * @param radix * @returns uuid * eg: createUUID(8, 2) "01001010& ...
- linux下使用svn
安装:apt-get install subversion CHECKOUT 将文件checkout到本地目录 svn checkout path(path是服务器上的目录)例如:svn checko ...
- nginx日志切割并使用flume-ng收集日志
nginx的日志文件没有rotate功能.如果你不处理,日志文件将变得越来越大,还好我们可以写一个nginx日志切割脚本来自动切割日志文件.第一步就是重命名日志文件,不用担心重命名后nginx找不到日 ...
- 【英语】Bingo口语笔记(65) - 我也是系列
- Oracle 11g对大表中添加DEFAULT值的NOT NULL字段速度有大幅度的提升
在一张2000万的表上增加了一个字段并字段一个默认值,执行这条语句(alter table tablename add new_col default ‘col’)一个小时没有执行完,问我有没有其他解 ...
- RabbitMQ链接不上异常
链接代码 项目启动报的异常 本地main方法链接报的异常 网上查询原因 问题说明及解决方案: 网上原因很多,最终原因都是连接不到数据库造成的. 1.查看防火墙 2.tomcat端口是否屏蔽 3.查看连 ...
- Hadoop学习总结之四:Map-Reduce的过程解析
转:http://www.cnblogs.com/forfuture1978/archive/2010/11/19/1882268.html