CodeForces - 622A A. Infinite Sequence(简单思路题)

题目链接:https://codeforces.com/problemset/problem/622/A
题目大意:有个数列: *1.  1,2. 1,2,3. 1,2,3,4.  ...
求第n个位置的数为多少
//因为题目是一个接一个的等差数列 先求出n所在的小数列中的最大值k 然后求除了k所在序列
//之前的所有数列的项数之和 因为这个数列从1开始所以直接用n-k*(k-1)/2得出结果
#include 
#include 
#include 
#include 

using namespace std;
int main()
{
   long long int n,k=1;
   scanf("%lld",&n);
   while(k)
   {//求出n所在数列项数
       if(k*(k+1)/2>=n) break;
       k++;
   }
   printf("%lld\n",n-k*(k-1)/2);//输出结果
   return 0;
}

你可能感兴趣的:(ACM寒假欢乐赛)