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. 打破基于OpenResty的WEB安全防护(CVE-2018-9230)

    原文首发于安全客,原文链接:https://www.anquanke.com/post/id/103771 0x00 前言 ​ OpenResty® 是一个基于 Nginx 与 Lua 的高性能 We ...

  2. ASP正则匹配方法

    方法二:找到匹配的进行替换 ip="127.0.0.1" Function ReplaceTest(str,patrn, replStr) Dim regEx, str1 Set ...

  3. psutil的使用

    psutil是Python中广泛使用的开源项目,其提供了非常多的便利函数来获取操作系统的信息. 此外,还提供了许多命令行工具提供的功能,如ps,top,kill.free,iostat,iotop,p ...

  4. [JS] console.time() - 计时器构造函数及如何计时

    概述 使用计时器可以对代码运行过程进行测速.你可以给每个计时器取一个名字,每个页面上最多可以运行一万个计时器.当你使用计时器名字调用 console.timeEnd() 函数时,浏览器会返回一个毫秒值 ...

  5. 122、详解Glide图片加载库常用方法

    转载:http://blog.csdn.net/android_xiong_st/article/details/53129256 Glide加载网络图片, 显示的还是以前的图片! (最全解决方案!) ...

  6. 脚本学习 game.sh

    #!/bin/bash #game_error.sh ]]; then #$#表示参数个数 -lt小于 echo "Usage: game_error.sh time[20170710]&q ...

  7. python基础---->python的使用(四)

    这里记录一下python关于网络的一些基础知识.不知为何,恰如其分的话总是姗姗来迟,错过最恰当的时机. python中的网络编程 一.socket模板创建一个 TCP 服务器 import socke ...

  8. 升级后重启造成fsck.ext3: Unable to resolve UUID

    这篇文章帮了我的大忙了:转载自:http://wilber82.blog.51cto.com/1124820/724472 今天在做服务器补丁部署,有一台ESX4.1的服务器在升级后重启过程中挂了,通 ...

  9. psr-4

    自动加载: <?php function autoload($className) { $className = ltrim($className, '\\'); $fileName = ''; ...

  10. php strpos(), stripos(),strrpos(), strripos()的区别

    strpos(), 左边开始,字符出现第一个位置,区分大小写: stripos(),不区分大小写: strrpos(), 左边开始,字符出现,最后一个位置,区分大小写: strripos()不区分大小 ...