第2题高效做法:首先用下三角求出所在的行列,再用等差乘以等比前n项求和算出对应的数值。   源自博客:http://blog.csdn.net/yuhua_zhou/article/details/77601124

#include<iostream>  
#include<string>
#include<cmath>  
using namespace std;
int main()
{
    long long k;
    while (cin >> k)
    {
        long long row = floor((-1.0 + sqrt(1.0 + 8.0 * k)) / 2.0);
        long long col;
        if (k - (1 + row)*row / 2>0)
        {
            col = k - (1 + row)*row / 2;
        }
        else
        {
            col = row;
        }
        long long sum = 0; 
        int q = 10;
        long long n = 0;
        while(sum < col)
        {
            n++;
            sum = ( n * 9 * powl(q, n) - 9 - (9 * 10 * (1 - powl(q, n - 1)) / (1 - q)) ) / (q - 1);
        }
        long long n_last = n - 1;
        long long sum_last = (n_last * 9 * powl(q, n_last) - 9 - (9 * 10 * (1 - powl(q, n_last - 1)) / (1 - q))) / (q - 1);
        long long d_col = col - sum_last - 1;//d_col大于等于零的整数
        long long digit = powl(10 , n - 1) + floorl(d_col / n);
        string str = to_string(digit);
        cout << str[d_col % n] << endl;
    }
    return 0;
}