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. 梦想CAD控件安卓界面控制

    CAD控件界面上所有元素都可以控制显示或隐藏,下面将逐一介绍详细用法. 设置工具文件 MxFunction.setToolFile 设置工具文件.详细说明如下: 参数 说明 String sFile ...

  2. for循环,字典遍历(二)

    #通过列表值,定义一个字典,来获取key和value str_list = [1,3,5,7,9,'i',9,'o',7,'i'] str_dict = {} for i in str_list: # ...

  3. 微服务网关从零搭建——(一)创建测试api以及api自动注入consul

    本系列编写目的纯属个人开发记录  以下代码均为demo级 如有需要 请自行优化 代码完整包由于公司电脑加密 无法上传整包的demo文件 consul 开发环境简易处理 consul 下载地址 : ht ...

  4. 树状数组 & lowbit()

    看了很多大佬的博客,每看一篇博客懂一部分,总算是大概理解了树状数组这个神奇又强大的东西: 在这里我做个整合,把我认为好的部分摘录下来: 参考博客1:https://blog.csdn.net/flus ...

  5. 字符串匹配「 KMP 算法 」

    引言 众所周知,字符串无论是在 OI 中还是别的计算机领域都占有比较大的比重,今天说的就是一个关于匹配字符串的算法——「 KMP 算法 」. 0x00 KMP 算法用于解决这样的一类问题:给定一个文本 ...

  6. Manacher算法(马拉车算法)浅谈

    什么是Manacher算法? 转载自百度百科 Manachar算法主要是处理字符串中关于回文串的问题的,它可以在 O(n) 的时间处理出以字符串中每一个字符为中心的回文串半径,由于将原字符串处理成两倍 ...

  7. AWK简单使用方法

    1. 命令格式 gawk [OPTIONS] 'program' FILES.... program:'PATTERN{ACTION}' 一条awk命令中,PATTERN和ACTION,至少存在一个才 ...

  8. buf.readInt32BE()

    buf.readInt32BE(offset[, noAssert]) buf.readInt32LE(offset[, noAssert]) offset {Number} 0 <= offs ...

  9. HTML5中Canvas概述

    一.HTML5 Canvas历史 Canvas的概念最初是由苹果公司提出的,用于在Mac OS X WebKit中创建控制板部件(dashboard widget).在Canvas出现之前,开发人员若 ...

  10. vb 运行ppt示例代码

    来源:http://support.microsoft.com/kb/222929 通过使用 PowerPoint 中的自动运行功能,您可以以编程方式打印.显示幻灯片及执行以交互式执行的大多数事情.按 ...