HDU 1597 find the nth digit

题解:通过n>=(x+1)*(x)/2解出向下取整,再计算出n在该串中位置,模9输出即可:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    long long k,temp,i,n;
    while(cin>>k)
    {
        while(k--)
        {
            cin>>n;
            temp=(-1+sqrt(double(1+8*(n-1))))/2;
            if(temp%2)n-=((1+temp)/2)*temp;
            else n-=(1+temp)*(temp/2);
            n%=9;
            if(n==0)n=9;
            cout<<n<<endl;
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/forever97/p/3541205.html