Infinite Sequence

Crawling in process...
Crawling failed
Time Limit:1000MS    
Memory Limit:262144KB    
64bit IO Format:
%I64d & %I64u

Description

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.

Input

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.

Output

Print the element in the n-th position of the sequence (the elements are numerated from one).

Sample Input

Input
  1. 3
Output
  1. 2
Input
  1. 5
Output
  1. 2
Input
  1. 10
Output
  1. 4
Input
  1. 55
Output
  1. 10
Input
  1. 56
Output
  1. 1
  1.  
  1. 有这样一个序列,1,1,2,1,2,3,,,,,输出数列中的第n个数
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8. 	__int64 n;
  9. 	while(cin>>n)
  10. 	{
  11. 		__int64 temp;
  12. 		for(__int64 i=1;n>0;i++)
  13. 		{
  14. 			temp=n;
  15. 			n-=i;
  16. 		}
  17. 		cout<<temp<<endl;
  18. 	}
  19. 	return 0;
  20. }

Codeforces--622A--Infinite Sequence(数学)的更多相关文章

  1. codeforces 622A Infinite Sequence

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. codeforces 1260C. Infinite Fence (数学or裴蜀定理)

    只需要验证小间隔在大间隔之间有没有连续的k个 设小间隔为a,大间隔为b,那么a在b之间出现的次数在\(\lfloor \frac{b}{a}\rfloor\)或者\(\lfloor \frac{b}{ ...

  3. codeforces 622A A. Infinite Sequence (二分)

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  5. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  6. CodeForces 622 A.Infinite Sequence

    A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. codeforces 675A A. Infinite Sequence(水题)

    题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...

  8. 【arc071f】Infinite Sequence(动态规划)

    [arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...

  9. A - Infinite Sequence

    Problem description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2,  ...

  10. Codeforces 601B. Lipshitz Sequence(单调栈)

    Codeforces 601B. Lipshitz Sequence 题意:,q个询问,每次询问给出l,r,求a数组[l,r]中所有子区间的L值的和. 思路:首先要观察到,斜率最大值只会出现在相邻两点 ...

随机推荐

  1. 梦想3D控件 2018.7.26更新

    下载地址: http://www.mxdraw.com/ndetail_108.html 1.  编写所有接口函数使用的CHM文档 2.  增加交互绘制功能 3.  增加案例弧形窗建模案例 4.  增 ...

  2. wpf 自定义单选按钮 RadioButton

    新建RadioButtonEx.cs public class RadioButtonEx : RadioButton { public Geometry SelectIcon { get { ret ...

  3. Leetcode724:寻找数组的中心索引(java、python3)

    寻找数组的中心索引 给定一个整数类型的数组 nums,请编写一个能够返回数组"中心索引"的方法. 我们是这样定义数组中心索引的:数组中心索引的左侧所有元素相加的和等于右侧所有元素相 ...

  4. Python基础之简介

    参考原文 廖雪峰Python教程 什么是Python? Python是一种计算机程序设计语言,又被称为胶水语言,它是高级的编程语言. Python能干什么? 网站后端程序员.自动化运维.数据分析师.游 ...

  5. 39页第7题 计算2的i次方之和

    /*计算2的i次方之和*/ #include<stdio.h> #include<math.h>/*调用math.h文件中的函数*/ int main(void) { int ...

  6. python面向对象的特点,类定义等,私有属性、公有属性、成员属性

    引子:类的对象在内存中的表示def dog(name,dog_type): def bark(d): print(d,'wang wang wang ...') data = { 'name':nam ...

  7. Python字符串(Python学习笔记02)

    字符串 Python 3 中的字符串可以使用双引号或单引号标示,如果字符串出现引号,则可以使用 \ 来去除引号标示字符串的作用. 几种字符串的表示方法: str1 = "hello" ...

  8. JavaScript 面向对象的编程(二) 类的封装

    类的定义 方式一 var Book = function(id, name, price){ //私有属性,外部不能直接访问 var num = 1; //私有方法, function checkId ...

  9. tmux使用入门

    tmux是Linux中窗口管理程序,适用于终端复用,尤其适合远程连接.最近,我正苦闷与ssh自动超时退出和broken pipe,决定投入tmux怀抱. 使用tmux最直接的好处,便是可以在一个远程连 ...

  10. 非常适合新手的jq/zepto源码分析08---ajax的封装

    1.现在看看对JSONP的封装 $.ajaxJSONP = function(options, deferred){ if (!('type' in options)) return $.ajax(o ...