zoukankan      html  css  js  c++  java
  • codeforces 622A Infinite Sequence

    A. Infinite Sequence
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    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).

    Examples
    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,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
    ",m);
    	} 
    	return 0;
    }
    

      

  • 相关阅读:
    LG gram 双系统全指南
    离散数学读书记录
    研究小报告:掺杂硅脂对处理器散热能力的影响
    SICP 课程总结 & 复习
    maxHeap 的 python 实现
    KDD Cup 2018 冠军团队 思路分享
    mergeSort, quickSort, shellSort 的 python 实现
    数据集-搜集
    【NOIP2018模拟赛】
    【NOIP2018 模拟】
  • 原文地址:https://www.cnblogs.com/tonghao/p/5236162.html
Copyright © 2011-2022 走看看