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 端口占用情况

    1,查看8010端口是否被占用 [root@cloud ~]# netstat -an|grep 8010 tcp 0 0 0.0.0.0:8010 0.0.0.0:* LISTEN 2,查看8010 ...

  2. iOS开发-NSDictionary

    判断一个字典中是否存在某个key,有两种方法: 方法一: if ([dictionary allKeys] containsObject: key]){ // cotains key operatio ...

  3. Linux 常用文件

    /etc/exports /etc/services /etc/sysctl.conf /etc/logrotate.conf /etc/docker/key.json /etc/docker/dae ...

  4. CentOS7--使用yum安装和管理软件

    yum是红帽软件包管理器,它能能够查询,安装和卸载软件包,以及将整个系统更新到最新的可用版本.Yum可以在安装的过程中自动解决依赖关系. 1. 检查和更新软件包 1.1 查询更新 查看系统上哪些已安装 ...

  5. C++ template —— trait与policy类(七)

    第15章 trait与policy类---------------------------------------------------------------------------------- ...

  6. 普通for循环和增强for循环的区别

    1.普通for循环:自行维护循环次数,循环体自行维护获取元素的方法: int[] array = new int[]{1,2,3,4,5}; //int[] array ={1,2,3,4,5} ; ...

  7. Matlab练习——寻找完全数

    clc; clear; wq = []; : sum = ; k = ; : i / sum = sum + j; end end == i wq=[wq i]; end end disp(['2至1 ...

  8. php原生实现图片上传和查看

    先上源码:upload_file.php <html> <body> <form action="upload_file.php" method=&q ...

  9. echarts.js多图表数据展示使用小结

    echarts api文档: http://echarts.baidu.com/echarts2/doc/doc.html echarts demo示例: http://echarts.baidu.c ...

  10. String 类实现 以及>> <<流插入/流提取运算符重载

    简单版的String类,旨在说明>> <<重载 #include <iostream> //#include <cstring>//包含char*的字符 ...