zoukankan      html  css  js  c++  java
  • Codeforces--622A--Infinite Sequence(数学)

    

    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;
    }

  • 相关阅读:
    POJ题目分类(转)
    ACM训练计划建议(转)
    ACM题集以及各种总结大全(转)
    HDU 2673 (排序)
    HDU 1391 number steps(找规律,数学)
    HDU 1280 前m大的数(排序,字符串)
    HDU 1236 排名(结构体+排序)
    2015 湘潭大学程序设计比赛(Internet)H题-括号匹配
    最短路---hdu2544
    Rescue--hdu1242
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273394.html
Copyright © 2011-2022 走看看