首页 > 其他 > 详细

[CF1177B] Digits Sequence (Hard Edition) - 数学

时间:2020-05-04 11:53:52      阅读:64      评论:0      收藏:0      [点我收藏+]

Description

序列 \(123456789101112131415161718192021222324252627282930313233343536...\) 是无穷无尽的,现在你要输出它的第 \(k\) 项。\(k \le 10^{12}\)

Solution

分步处理

  1. 找到答案所在数的位数
  2. 找到答案所在数在当前位数中排第几
  3. 找到答案在答案所在数是第几位
#include <bits/stdc++.h>
using namespace std;

#define int long long
int k;

signed main() {
    cin>>k;
    if(k<10) {
        cout<<k;
        return 0;
    }
    int len=1,cnt=9,pos=0;
    while(len*cnt+pos < k) {
        pos+=len*cnt;
        ++len;
        cnt*=10;
    }
    k-=pos+1;
    int val=k/len+pow(10,len-1);
    cout<<(val/(int)pow(10,len-k%len-1))%10;
}

[CF1177B] Digits Sequence (Hard Edition) - 数学

原文:https://www.cnblogs.com/mollnn/p/12825684.html

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