codeforces 622A 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 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.
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.
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 题意:一个数列 1,1,2,1,2,3,1,2,3,4,1,2,3,4,5 .....以此类推给你一个数n问第n个数是多少
题解:由题知数列的数的个数为1+2+3+4+5+6+.......所以求出第n个数是哪个子序列里的即可(第一个子序列中一个数第二个字序列里两个数第三个里三个数....)
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 5100
#define mod 10007
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int main()
{
LL n,m,j,i,k,t,ans;;
while(scanf("%lld",&n)!=EOF)
{
ans=0;
for(i=1;i<2*sqrt(n)+1;i++)
{
if((i*(i+1)/2)>=n)
{
ans=i;
break;
}
}
m=ans*(ans-1)/2;
m=n-m;
printf("%lld\n",m);
}
return 0;
}
codeforces 622A Infinite Sequence的更多相关文章
- codeforces 622A A. Infinite Sequence  (二分)
		
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
 - 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 622  A.Infinite Sequence
		
A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
 - codeforces 675A A. Infinite Sequence(水题)
		
题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...
 - 【arc071f】Infinite Sequence(动态规划)
		
[arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...
 - A - Infinite Sequence
		
Problem description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, ...
 - Codeforces 601B. Lipshitz Sequence(单调栈)
		
Codeforces 601B. Lipshitz Sequence 题意:,q个询问,每次询问给出l,r,求a数组[l,r]中所有子区间的L值的和. 思路:首先要观察到,斜率最大值只会出现在相邻两点 ...
 - 【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)/ ...
 
随机推荐
- 5 commands to check memory usage on Linux
			
Memory Usage On linux, there are commands for almost everything, because the gui might not be always ...
 - poj3307
			
可以证明,每个符合的数都由2,3,5,7相乘得到. 依据猜想:下一个出现的数是由前面某个数乘上这几个数之一得到的新的数. 假设之前的数均满足序列,则因为下一个数必有2,3,5,7相乘得到,而这个数之前 ...
 - EF4.0和EF5.0增删改查写法区别
			
1 public T AddEntity(T entity) 2 { 3 //EF4.0的写法 4 添加实体 5 //db.CreateObjectSet<T>().AddObject(e ...
 - jQuery实战读书笔记(备忘录)
			
选择器备忘: | :even 匹配所有索引值为偶数的元素,从 0 开始计数 :odd 匹配所有索引值为奇数的元素,从 0 开始计数 实例——设置table交替行变色: <script type= ...
 - 配置ORACLE 客户端连接到数据库
			
--================================= -- 配置ORACLE 客户端连接到数据库 --================================= Oracle ...
 - Linux 平台下 YUM 源配置 手册
			
Redhat/Centos 系的Linux 平台,推荐使用YUM 来安装相关依赖包. 安装方式有两种,一种是使用本地的YUM,一种使用在线的YUM. 1 在线YUM 源 如果操作系统能 ...
 - Top Android App使用的组件 3
			
8684公交 AdChina:com.adchina:易传媒广告平台 AdsMogo:com.adsmogo:芒果移动广告平台 大姨吗 AChartEngine:org.achartengine:An ...
 - IOS AVAUDIOPLAYER   播放器使用
			
1. 导入 AVFoundation.framework 2.导入头文件 #import <AVFoundation/AVFoundation.h> 3. player = [[AVAu ...
 - 【LeetCode 209】Minimum Size Subarray Sum
			
Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...
 - 有关SQLite的substr函数的笔记
			
官方参考文档:SQLite Query Language: Core Functions http://www.sqlite.org/lang_corefunc.html 测试SQL语句: ,) AS ...