题目链接:http://codeforces.com/problemset/problem/1177/B

B. Digits Sequence (Hard Edition)

Let's write all the positive integer numbers one after another from 11 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...

Your task is to print the kk-th digit of this sequence.

Input

The first and only line contains integer kk (1≤k≤10121≤k≤1012) — the position to process (11-based index).

Output

Print the kk-th digit of the resulting infinite sequence.

Examples

input

7

output

7

input

21

output

5

题意概括:把正整数按顺序排成一个字符串,求第n个字符是什么

解题思路:一位正整数有9个,两位有90个,三位900个,先求出这个数是几位的,然后求出是第几个,最后求出是这个数的第几位

#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
#define MIN(a,b,c) (a<b?(a<c?a:c):(b<c?b:c))
using namespace std;typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
const int MAXN = 2750131;
ll T,n,m,i,j;
ll gcd(ll p,ll q)
{return q==0?p:gcd(q,p%q);}ll g[200005];int main()
{ios::sync_with_stdio(false);ll a[20];ll k=1,s=1,sum=9;for(i=0;s<1e12;i++){a[i]=s*sum*k;s*=10;k++;//   cout<<a[i]<<endl;}cin>>n;if(n<10){cout<<n<<endl;return 0;}sum=0;i=0;k=1;s=1;ll m=n;while(m>a[i]){m-=a[i];i++;k++;s=pow(10,i);sum=s-1;}
//  cout<<m<<endl;ll ans=(m)/k+sum;if(m%k){ans++;}
//  cout<<ans<<endl;ll sk=m%k;if(sk==0){sk=k;}//cout<<sk<<" "<<k<<endl;while(ans>0){// cout<<ans<<" "<<k<<" "<<sk<<endl;if(sk==k){cout<<ans%10<<endl;break;}else{ans/=10;k--;}} return 0;
} 

codeforces 1177B相关推荐

  1. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  2. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  3. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  4. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  5. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  6. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  7. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

最新文章

  1. 从车联网到工业智联网
  2. 谈谈大家对PHP框架的各种误解
  3. Spring实现web开发的环境搭建
  4. NOIP模拟测试39,思维禁锢专场「工业题·玄学题·卡常题」
  5. 用于检测敏感词的 PHP 扩展
  6. c++ for each 遍历tuple
  7. Redis 实用技术——事务
  8. 4.2 算法之数论 185 反正切函数的应用 scratch
  9. 日文简历 模板
  10. 21天打卡活动 leetcode 301
  11. Threejs实现3d地球记录(5)
  12. 冰羚-README.md翻译
  13. 夜神安卓模拟器怎么设置代理
  14. 相亲小程序如何做到年入百万?盈利模式是什么?
  15. ES6的Lambda表达式
  16. writeline是什么意思_write是什么意思_write的翻译_音标_读音_用法_例句_爱词霸在线词典...
  17. java计算机毕业设计宠物店管理系统设计与实现(附源码、数据库)
  18. 副驾驶的意义_副驾驶对女人的意义是什么样的?
  19. 云计算虚拟化技术总结
  20. 音频插件包:Unfiltered Audio Plugins Bundle for Mac

热门文章

  1. 三、HTML5之文本元素
  2. 深度学习之图像分类(十九)-- Bottleneck Transformer(BoTNet)网络详解
  3. 快手官宣全员开启大小周?996、997,网友:「国产式加班」花样真多!
  4. bt2mag_粉碎Mag CSS问答#2
  5. Delphi王者归来!2018年Delphi精英奖揭晓!
  6. springCloud五大神兽(思维导图)
  7. 关于电脑pe系统介绍
  8. 【逗老师带你学IT】PRTG监控系统配合树莓派采集企业内部无线网络质量
  9. C++洛谷题解(28)——P5717
  10. Java虚拟机学习与总结(二)