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
3
Output
2
Input
5
Output
2
Input
10
Output
4
Input
55
Output
10
Input
56
Output
1

有这样一个序列,1,1,2,1,2,3,,,,,输出数列中的第n个数
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
__int64 n;
while(cin>>n)
{
__int64 temp;
for(__int64 i=1;n>0;i++)
{
temp=n;
n-=i;
}
cout<<temp<<endl;
}
return 0;
}

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. Python常用的内建模块

    PS:Python之所以自称“batteries included”,就是因为内置了许多非常有用的模块,无需额外安装和配置,即可直接使用.下面就来看看一些常用的内建模块. 参考原文 廖雪峰常用的内建模 ...

  2. JAVA基础——toString()方法

    toString()方法返回反映这个对象的字符串 因为toString方法是Object里面已经有了的方法,而所有类都是继承Object,所以“所有对象都有这个方法”. 它通常只是为了方便输出,比如S ...

  3. Listview异步加载图片之优化篇

    在APP应用中,listview的异步加载图片方式能够带来很好的用户体验,同时也是考量程序性能的一个重要指标.关于listview的异步加载,网上其实很多示例了,中心思想都差不多,不过很多版本或是有b ...

  4. 洛谷——P2171 Hz吐泡泡

    P2171 Hz吐泡泡 题目描述 这天,Hz大大心血来潮,吐了n个不同的泡泡玩(保证没有重复的泡泡).因为他还要写作业,所以他请你帮他把这些泡泡排序成树(左子树<=根<右子树).输出它的后 ...

  5. UVA - 1623 Enter The Dragon(贪心)

    题目: 思路: 读完题之后有了以下想法: 当遇到下雨的天,就找这个湖泊上一次下雨满了之后又一次不下雨的日期.有就在这个日期下记录被神龙喝干的湖的编号,没有就是不符合题意. 这个想法是对的,但是却被代码 ...

  6. Python学习-while循环练习

    1.计算1-100的和 i = 1; total = 0; while i <= 100: total = total + i; i = i + 1; print(total); 2.打印出1- ...

  7. db2 in out inout

    总结: in  给存储过程传的参数,传一个确定的值 out  传的时候传一个非确定的变量v或者“?”  .在存储过程里面计算一个结果赋给v,这个变量v在存储过程执行完之后就是一个确定的值了. inou ...

  8. ubuntu 常见的操作命令

    原博客地址为:https://blog.csdn.net/qq_33421080/article/details/76551554 1.cd命令: cd:切换到当前用户根目录,默认[/home/用户名 ...

  9. python 基础知识及运算符

    可变类型:列表.字典 不可变类型:整形.字符串.元组 标示符: 1.字母数字和下划线组成 2.不能以数字开头 3.区分大小写 4.不能以保留字命名 变量: 1.用描述性的单词命名变量,不要用保留字.汉 ...

  10. linux下的进程

    一.进程的基础: 1.程序:程序是一些保存在磁盘上的指令的有序集合: 2.进程:进程是程序的一次执行过程: 3.进程与程序的关系:①.程序是静态的,进程是动态的:  ②.一个程序可以对应多个进程:   ...