Numerical Sequence (easy version)

Stella981
• 阅读 550

http://codeforces.com/problemset/problem/1216/E1

E1. Numerical Sequence (easy version)

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The only difference between the easy and the hard versions is the maximum value of k

.

You are given an infinite sequence of form "112123123412345…

" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 1 to 1, the second one — from 1 to 2, the third one — from 1 to 3, …, the i-th block consists of all numbers from 1 to i

.

So the first 56

elements of the sequence are "11212312341234512345612345671234567812345678912345678910". Elements of the sequence are numbered from one. For example, the 1-st element of the sequence is 1, the 3-rd element of the sequence is 2, the 20-th element of the sequence is 5, the 38-th element is 2, the 56-th element of the sequence is 0

.

Your task is to answer q

independent queries. In the i-th query you are given one integer ki. Calculate the digit at the position ki

of the sequence.

Input

The first line of the input contains one integer q

(1≤q≤500

) — the number of queries.

The i

-th of the following q lines contains one integer ki (1≤ki≤109)

— the description of the corresponding query.

Output

Print q

lines. In the i-th line print one digit xi (0≤xi≤9) — the answer to the query i, i.e. xi should be equal to the element at the position ki

of the sequence.

Examples

Input

Copy

5
1
3
20
38
56

Output

Copy

1
2
5
2
0

Input

Copy

4
2132
506
999999999
1000000000

Output

Copy

8
2
9
8

Note

Answers on queries from the first example are described in the problem statement.

题意:在数列中查找第i个数是多少。

//#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <stdio.h>
    #include <queue>
    #include <stack>;
    #include <map>
    #include <set>
    #include <string.h>
    #include <sstream>
    #include <vector>
    #define ME(x , y) memset(x , y , sizeof(x))
    #define SF(n) scanf("%d" , &n)
    #define rep(i , n) for(int i = 0 ; i < n ; i ++)
    #define INF  0x3f3f3f3f
    #define mod 1000000007
    #define PI acos(-1)
    using namespace std;
    typedef long long ll ;
    int l[80009];
    int c[80009];
    int s[80009];
     
    int length(int x)
    {
        if(x >= 10000)
        {
            return 5 ;
        }
        else if(x >= 1000)
        {
            return 4 ;
        }
        else if(x >= 100)
            return 3 ;
        else if(x >= 10)
            return 2 ;
        else
            return 1 ;
    }
     
    void init()
    {
        for(int i = 1 ; i <= 60000 ; i++)
        {
            l[i] = length(i);
            c[i] = c[i-1]+l[i];
            s[i] = s[i-1]+c[i];
        }
    }
     
    int main()
    {
        int t ;
        init();
        scanf("%d" , &t);
        while(t--)
        {
            int n;
            scanf("%d" , &n);
            int index = lower_bound(s+1 , s+60000 , n) - s;
            n -= s[index-1];
            index = lower_bound(c+1 , c+index , n) - c;
            n -= c[index-1] ;
            n = l[index] - n ;
            while(n--)
            {
                index /= 10 ;
            }
            printf("%d\n" , index%10);
        }
     
     
        return 0;
    }
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Wesley13 Wesley13
2年前
java将前端的json数组字符串转换为列表
记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang
kenx kenx
2年前
个人博客开发之blog-api项目统一结果集api封装
前言由于返回jsonapi格式接口,所以我们需要通过javabean封装一个统一数据返回格式,便于和前端约定交互,状态码枚举ResultCodejavapackagecn.soboys.core.ret;importlombok.Getter;/@authorkenx@version1.0@date2021/6/1715:35
Souleigh ✨ Souleigh ✨
2年前
前端性能优化 - 雅虎军规
无论是在工作中,还是在面试中,web前端性能的优化都是很重要的,那么我们进行优化需要从哪些方面入手呢?可以遵循雅虎的前端优化35条军规,这样对于优化有一个比较清晰的方向.35条军规1.尽量减少HTTP请求个数——须权衡2.使用CDN(内容分发网络)3.为文件头指定Expires或CacheControl,使内容具有缓存性。4.避免空的
Stella981 Stella981
2年前
SVG跟随父级DIV自适应
后台返回过来的是这样的SVG标签<svgwidth"100%"height"100%"version"1.1"xmlns"http://www.w3.org/2000/svg"<gtransform"translate(00)"
Easter79 Easter79
2年前
SVG跟随父级DIV自适应
后台返回过来的是这样的SVG标签<svgwidth"100%"height"100%"version"1.1"xmlns"http://www.w3.org/2000/svg"<gtransform"translate(00)"
Stella981 Stella981
2年前
Codeforces 1091D New Year and the Permutation Concatenation 找规律,数学 B
Codeforces1091DNewYearandthePermutationConcatenation   https://codeforces.com/contest/1091/problem/D题目:  Letnbeaninteger.Considerallpermutationsonintege
Stella981 Stella981
2年前
CodeForces165E 位运算 贪心 + 状压dp
http://codeforces.com/problemset/problem/165/E题意 两个整数 _x_ 和 _y_ 是 兼容的,如果它们的位运算"AND"结果等于0,亦即 _a_ & _b_  0 。例如,数 90 (10110102) 和 36 (1001002) 是兼容的,因为 10110102 & 1001002  0
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这