# Number Sequence

Description

A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one after another.

For example, the first 80 digits of the sequence are as follows:

11212312341234512345612345671234567812345678912345678910123456789101112345678910

Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by one line for each test case. The line for a test case contains the single integer i (1 ≤ i ≤ 2147483647)

Output

There should be one output line per test case containing the digit located in the position i.

Sample Input

2

8

3

Sample Output

2

2

- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答

*1*条回答

#### 相关推荐

- 4年前回答 1 已采纳 Description A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one after another. For example, the first 80 digits of the sequence are as follows: 11212312341234512345612345671234567812345678912345678910123456789101112345678910 Input The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by one line for each test case. The line for a test case contains the single integer i (1 ≤ i ≤ 2147483647) Output There should be one output line per test case containing the digit located in the position i. Sample Input 2 8 3 Sample Output 2 2
- 回答 2 已采纳 A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). 超过49个数之后一定会出现和之前的数组合相同的情况，这个我可以了解，但是 为什么最多经过49个数之后一定会出现周期呢？智商太低了，跪求解释
- 5年前回答 1 已采纳 Description Given m sequences, each contains n non-negative integer. Now we may select one number from each sequence to form a sequence with m integers. It's clear that we may get n ^ m this kind of sequences. Then we can calculate the sum of numbers in each sequence, and get n ^ m values. What we need is the smallest n sums. Could you help us? Input The first line is an integer T, which shows the number of test cases, and then T test cases follow. The first line of each case contains two integers m, n (0 < m <= 100, 0 < n <= 2000). The following m lines indicate the m sequence respectively. No integer in the sequence is greater than 10000. Output For each test case, print a line with the smallest n sums in increasing order, which is separated by a space. Sample Input 1 2 3 1 2 3 2 2 3 Sample Output 3 3 4
- 5年前回答 1 已采纳 Description Physicists study atoms hidden in a ``black box". So as to get information on the position of atoms in the box, they cast a laser beam through gates and look at where light gets out from the box. As a computer scientist you are (kindly) requested to interpret the physicists experiments. Problem By weighting the box, the physicists already managed to count how many atoms there are (K = 5) . Besides, they adopt a grid model. First, the box is quite simple: this is a flat, N x N box (N = 8) , with 32 = 4 * N gates, which are numbered as shown above. Additionally, following the famous ``no border principle" and a loose application of Pauli exclusion principle, the physicists restrict the available positions to the central 36 = (N - 2)2 positions, and they assume that no two atoms occupy the same position. Besides, in the grid model, light is also quite simple: Light travels at infinite speed in either of the fourth directions, east, north, west or south. For instance, if the beam enters the box from the west, then it travels eastward. In the absence of obstacles, light goes straight ahead. See the beam entering at gate 7. In case it enters a position occupied by an atom, light is absorbed. Then, there is no output gate. See the beam entering at gate 3. Light is deviated by atoms. Before entering a position whose left (resp. right) neighbor contains an atom, light turns right (resp. left). See the beam entering at gate 0 for an example of a left deviation, and the beam entering at gate 29 for for an example of a right deviation. Absorption takes precedence over deviation. See the beam entering at position 27. When a beam is deviated both left and right at the same time, it turns back. See the beam entering at gate 10 and leaving at the same gate 10, because of such a double deviation. Laws of light combine. See the beam entering at gate 21, which is absorbed after a left deviation. Input Input is a log of experiments performed over a given box. The first line is an integer e (0 < e<=32) . Integer e is the number of experiments performed. Then, come e lines, each line being made of two integers. The first integer i is a gate number expressing that the beam enters the box at gate i . The second integer o is either a gate number, expressing that the beam leaves the box at gate o , or the integer `-1', expressing that the beam is absorbed. Output If the atom positions can be deduced from the experiments, then your program should output an ascii representation of the box, as N lines of N characters, with atoms being shown as `+' and empty positionsas `-' -- See the first example below. Otherwise, your program should output `NO' on a single line. Notice that `NO' is the correct answer in several situations. More specifically, the experiments may be contradictory (there does not exist a repartition of atoms compatible with the experiments) or non-concluding (there exist several repartitions of atoms compatible with the experiments). Sample Input 7 0 29 27 -1 21 -1 10 10 3 -1 16 7 6 12 Sample Output -------- ---++--- -------- -+-+---- -------- -----+-- -------- --------
- 4年前回答 3 已采纳 The EKG sequence is a sequence of positive integers generated as follows: The first two numbers of the sequence are 1 and 2. Each successive entry is the smallest positive integer not already used that shares a factor with the preceding term. So, the third entry in the sequence is 4 (being the smallest even number not yet used). The next number is 6 and the next is 3. The first few numbers of this sequence are given below. 1, 2, 4, 6, 3, 9, 12, 8, 10, 5, 15, 18, 14, 7, 21, 24, 16, 20, 22, 11, 33, 27 The sequence gets its name from its rather erratic fluctuations. The sequence has a couple of interesting, but non-trivial, properties. One is that all positive integers will eventually appear in the sequence. Another is that all primes appear in increasing order. Your job here is to _nd the position in the sequence of a given integer. Input Input consists of a number of test cases. Each case will be a line containing a single integer n, 1 1,000,000. Output Each test case should produce one line of output of the form: The number n appears in location p. where n is the number given and p is the position of n in the EKG sequence. You are guaranteed that p will be no larger than 1,000,000. Sample Input 12 21 2 33 100000 299977 0 Sample Output The number 12 appears in location 7. The number 21 appears in location 15. The number 2 appears in location 2. The number 33 appears in location 21. The number 100000 appears in location 97110. The number 299977 appears in location 584871.
- 回答 1 已采纳 Description Given a sequence of N ordered pairs of positive integers (Ai, Bi), you have to partition it into several contiguous parts. Let p be the number of these parts, whose boundaries are (l1, r1), (l2, r2), ... ,(lp, rp), which satisfy li =ri − 1 + 1, li ≤ ri, l1 = 1, rp = n. The parts themselves also satisfy the following restrictions: For any two pairs (Ap, Bp), (Aq, Bq), where (Ap, Bp) is belongs to the Tpth part and (Aq, Bq) the Tqth part. If Tp Aq. Let Mi be the maximum A-component of elements in the ith part, say Mi = max{Ali, Ali+1, ..., Ari}, 1 ≤ i ≤ p it is provided that where Limit is a given integer. Let Si be the sum of B-components of elements in the ith part. Now I want to minimize the value max{Si:1 ≤ i ≤ p} Could you tell me the minimum? Input The input contains exactly one test case. The first line of input contains two positive integers N (N ≤ 50000), Limit (Limit ≤ 231-1). Then follow N lines each contains a positive integers pair (A, B). It's always guaranteed that max{A1, A2, ..., An} ≤ Limit Output Output the minimum target value. Sample Input 4 6 4 3 3 5 2 5 2 4 Sample Output 9
- 4年前回答 1 已采纳 Problem Description Consider the aggregate An= { 1, 2, …, n }. For example, A1={1}, A3={1,2,3}. A subset sequence is defined as a array of a non-empty subset. Sort all the subset sequece of An in lexicography order. Your task is to find the m-th one. Input The input contains several test cases. Each test case consists of two numbers n and m ( 0< n<= 20, 0< m<= the total number of the subset sequence of An ). Output For each test case, you should output the m-th subset sequence of An in one line. Sample Input 1 1 2 1 2 2 2 3 2 4 3 10 Sample Output 1 1 1 2 2 2 1 2 3 1
- 4年前回答 1 已采纳 Problem Description Long long ago, there is a sequence A with length n. All numbers in this sequence is no smaller than 1 and no bigger than n, and all numbers are different in this sequence. Please calculate how many quad (a,b,c,d) satisfy: 1. 1≤a<b<c<d≤n 2. Aa<Ab 3. Ac<Ad Input The first line contains a single integer T, indicating the number of test cases. Each test case begins with a line contains an integer n. The next line follows n integers A1,A2,…,An. [Technical Specification] 1 <= T <= 100 1 <= n <= 50000 1 <= Ai <= n Output For each case output one line contains a integer,the number of quad. Sample Input 1 5 1 3 2 4 5 Sample Output 4
- 3年前xbgdzj的博客 Number Sequence Describe A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2…Sk. Each group Sk consists of a ...
- JAVA/C++的博客 一:杭电原题摘录 http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=2&problemid=8 二....很容易就能想到递归,但是超出内存 ...int fac(int a,int b,int n)//超出内存 ... f...
- Y_F_Wang的博客 NumberSequence Problem Description A number sequenceis defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of
- f_zyj的博客 ACM模版描述题解一看公式就知道这道题在51Nod上做过一次，于是按照老思路准备水过，可是却意外发现了自己曾经的写法实在是想当然了，如果不是这道题51Nod数据比较水，我一定过不去~~~以前在做这道题时，感觉循环一定...
- nyist_xushukui的博客 There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● a i ∈ 0,n0,n ● a i ≠ a j( i ≠ j ) For sequence a and sequence b, the integrating ...
- 研发之道的博客 Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 116886 Accepted Submission(s): 28442 Problem Description A number se
- 张起灵-小哥的博客 Problem Description：...A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). Input： ...
- 昨日明眸的博客 Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1803 Accepted Submission(s): 688 Problem Description A
- 13年前how to use ax Number Sequence
- LzyRapX的博客 Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 146218 Accepted Submission(s): 35530 Problem Description A number
- 5年前回答 1 已采纳 Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The first few are F2 = {1/2} F3 = {1/3, 1/2, 2/3} F4 = {1/4, 1/3, 1/2, 2/3, 3/4} F5 = {1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5} You task is to calculate the number of terms in the Farey sequence Fn. Input There are several test cases. Each test case has only one line, which contains a positive integer n (2 <= n <= 106). There are no blank lines between cases. A line with a single 0 terminates the input. Output For each test case, you should output one line, which contains N(n) ---- the number of terms in the Farey sequence Fn. Sample Input 2 3 4 5 0 Sample Output 1 3 5 9
- faithdmc的博客 There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequence b,