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[];
int c[];
int s[]; int length(int x)
{
if(x >= )
{
return ;
}
else if(x >= )
{
return ;
}
else if(x >= )
return ;
else if(x >= )
return ;
else
return ;
} void init()
{
for(int i = ; i <= ; i++)
{
l[i] = length(i);
c[i] = c[i-]+l[i];
s[i] = s[i-]+c[i];
}
} int main()
{
int t ;
init();
scanf("%d" , &t);
while(t--)
{
int n;
scanf("%d" , &n);
int index = lower_bound(s+ , s+ , n) - s;
n -= s[index-];
index = lower_bound(c+ , c+index , n) - c;
n -= c[index-] ;
n = l[index] - n ;
while(n--)
{
index /= ;
}
printf("%d\n" , index%);
} return ;
}

Numerical Sequence (easy version)的更多相关文章

  1. cf1216E2 Numerical Sequence (hard version)(思维)

    cf1216E2 Numerical Sequence (hard version) 题目大意 一个无限长的数字序列,其组成为\(1 1 2 1 2 3 1.......1 2 ... n...\), ...

  2. [CF1216E] Numerical Sequence hard version

    题目 The only difference between the easy and the hard versions is the maximum value of k. You are giv ...

  3. cf1216E2 Numerical Sequence (hard version) 二分查找、思维题

    题目描述 The only difference between the easy and the hard versions is the maximum value of k. You are g ...

  4. 【二分】CF Round #587 (Div. 3)E2 Numerical Sequence (hard version)

    题目大意 有一个无限长的数字序列,其组成为1 1 2 1 2 3 1.......1 2 ... n...,即重复的1~1,1~2....1~n,给你一个\(k\),求第\(k(k<=10^{1 ...

  5. CF1264D1 Beautiful Bracket Sequence (easy version)

    考虑在一个确定的括号序列中,我们可以枚举中间位置,按左右最长延伸出去的答案计算. 我们很自然的思考,我们直接维护左右两边,在删除一些字符后能够延伸的最长长度. 我们设\(f_{i,j}\)为\(i\) ...

  6. Ping-Pong (Easy Version)(DFS)

    B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. CF1225B1 TV Subscriptions (Easy Version)

    CF1225B1 TV Subscriptions (Easy Version) 洛谷评测传送门 题目描述 The only difference between easy and hard vers ...

  8. ZOJ 3868 - Earthstone: Easy Version

    3868 - Earthstone: Easy Version Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld ...

  9. Codeforces 1077F1 Pictures with Kittens (easy version)(DP)

    题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j ...

随机推荐

  1. Linux虚拟机网络设置问题

    使用的是VM 工作站15 和以前的不一样 没有什么虚拟机网络设置 :打开Edit->Virtual NetWork editor, 选中VMnet8,然后点击NAT Setting按钮,再点击D ...

  2. Golang在京东列表页实践总结

    Golang在京东列表页实践总结 作者:张洪涛 10余年软件开发和设计经验,曾就职于搜狐.搜狗.前matrixjoy公司联合创始人.甘普科技CTO. 目前线上状态 基于搜索实现: 全量数据,搜索结果不 ...

  3. 软件工程 in MSRA Code Search-第二次结对编程

    重现基线模型 我们选择了 code2vec 模型进行复现.该模型由 Uri Alon 等作者于 2018 年提出. 模型思路: 从代码与普通语言相比的特殊性入手,首先,对于输入的代码段,作者考虑到尽管 ...

  4. 多重背包的二进制优化——DP

    #include<cstdio> #include<cstring> #include<algorithm> #define LL long long using ...

  5. 【Java】使用@Valid+BindingResult进行controller参数校验

    @Valid @Valid注解用于校验,所属的包: javax.validation.Valid. 你可以定义实体,在实体的属性上添加校验规则,在API接收数据时添加@Valid注解,这时你的实体将会 ...

  6. UE4中显示AI Debug信息

    运行时,按下引号键('),就会出现AI的Debug信息,包含 AI Behavior Tree EQS Perception 四个大的分类,可以通过键盘上的1234键来显示和关闭相应的选项. 另外在E ...

  7. es之词库热更新解决方案

    1. 下载tomcat,作为远程词库的容器 , 需要在tomcat中配置词库 /webapp/ROOT这个路径下新建一个远程词库:​Vim hot.dicHot.dic中存放的就是实时热词 2.测试t ...

  8. Vuex的五个核心属性

    Vuex的五个核心属性 Vuex的五个核心概念 本文参考自Vue文档,说的非常详细,建议看文档. Vuex是什么? VueX 是一个专门为 Vue.js 应用设计的状态管理架构,统一管理和维护各个vu ...

  9. uniapp开发

    问题1:去掉导航条 给一个单独的页面隐藏顶部的 导航栏 可以在pages.json里 单独的路由style下面配置  "app-plus": {"titleNView&q ...

  10. oracle 如何更改密码的hash

    如何迁移oracle user的密码到新的环境,一下列出了方法: select name,spare4||';'||password pwd from sys.user$ where name = ' ...