Number Sequence
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 35251   Accepted: 10151

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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 32000
using namespace std;
int main()
{
int a[]= {,,,,,,,,};
long long b[N]= {},n,sum=;
int i,T,m,j,l,A,B;
for(i=; i<N; i++)
{
if(i<=)
b[i]=i;
else
{
m=;
l=(int)log10(i)+;
for(j=; j<l; j++)
{
m=m*+;
}
b[i]=(i-m)*l+b[m];
}
// sum+=b[i];
}
// printf("%lld\n",sum);确定b数组的范围,即N的大小;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
for(i=;i<N;i++)
{
if(n>b[i])
{
n-=b[i];
}
else
{
break;
}
}
for(i=;i<;i++)
{
if(n>a[i])
n-=a[i];
else
break;
}
A=n/i;
B=n%i;
if(B!=)
A+=;
else
B=i;
m=;
for(j=;j<i;j++)
m=m*+;
A=A+m;
char str[]= "";
sprintf(str,"%d",A);
printf("%c\n",str[B-]);
}
return ;
}

Number Sequence--POJ1019的更多相关文章

  1. POJ1019——Number Sequence(大数处理)

    Number Sequence DescriptionA single positive integer i is given. Write a program to find the digit l ...

  2. POJ1019 Number Sequence

    Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36256   Accepted: 10461 ...

  3. HDU 1005 Number Sequence

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. POJ 1019 Number Sequence

    找规律,先找属于第几个循环,再找属于第几个数的第几位...... Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total Submi ...

  5. HDOJ 1711 Number Sequence

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. Number Sequence

    Number Sequence   A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) ...

  7. [AX]AX2012 Number sequence framework :(三)再谈Number sequence

    AX2012的number sequence framework中引入了两个Scope和segment两个概念,它们的具体作用从下面序列的例子说起. 法国/中国的法律要求财务凭证的Journal nu ...

  8. KMP - HDU 1711 Number Sequence

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. hdu 1005:Number Sequence(水题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  10. Number Sequence 分类: HDU 2015-06-19 20:54 10人阅读 评论(0) 收藏

    Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...

随机推荐

  1. Linux 集群架构

    集群介绍 Keepalived 配置高可用集群

  2. Kafka producer拦截器(interceptor)

    Producer拦截器(interceptor)是个相当新的功能,它和consumer端interceptor是在Kafka 0.10版本被引入的,主要用于实现clients端的定制化控制逻辑. 对于 ...

  3. 细说php的异常和错误处理机制

    再谈php错误与异常处理 讲的非常好 w3school php异常处理机制 php错误异常处理详解 注: 关注set_error_handler() set_exception_handler() r ...

  4. make: Warning: File `Makefile' has modification time 17 s in the future

    linux下,make makefile文件的时候报警告: make: Warning: File `Makefile' has modification time 17 s in the futur ...

  5. 使用dom4j解析xml为json对象

    import java.util.List; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j. ...

  6. 【技术分享会】 @第五期 angularjs

    前言 AngularJS 最初由Misko Hevery 和Adam Abrons于2009年开发,后来成为了Google公司的项目.AngularJS弥补了HTML在构建应用方面的不足,其通过使用标 ...

  7. 使用__FILE__和__LINE__定位错误

    #include <stdio.h> int main() { printf("this fake error is in %s on line %d\n", __FI ...

  8. python基础---->python的使用(三)

    今天是2017-05-03,这里记录一些python的基础使用方法.世上存在着不能流泪的悲哀,这种悲哀无法向人解释,即使解释人家也不会理解.它永远一成不变,如无风夜晚的雪花静静沉积在心底. Pytho ...

  9. Intellij 部署项目java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    报错信息: org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener ...

  10. 跨域 - jsonp轻松搞定跨域请求

    1.jsonp轻松搞定跨域请求 vue中使用axios,遇到跨域我就蒙逼了.第一次真正意义上的尝试使用jsonp js中用 var myscript = document.createElement( ...