首页 > 其他 > 详细

HDU 1597 find the nth digit

时间:2014-02-09 16:25:26      阅读:313      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣
#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;
}
bubuko.com,布布扣

HDU 1597 find the nth digit

原文:http://www.cnblogs.com/forever97/p/3541205.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!