题目大意

考虑自然数构成的序列 $a$:$01234567891011\dots$,序列下标从 $0$ 开始,即 $a_0 =0, a_1 = 1$ 。
求 $a_n$($0\le n\le 10^{18}$)。

解法

设 $a_n$ 所在的数字为 $x(n)$ 。
首先不难求出 $x(n)$ 的位数, 设其为 $k$ 。
从而可以求出 $x(n)$ 是第几个 $k$ 位数,这样也就求出了 $x(n)$ 。
设 $x(n)$ 是第 $i$($i\ge 1$)个 $k$ 位数,则有
$$ i = \left\lceil \frac{n+1 - s_{k-1}}{k}\right\rceil $$
$\lceil a/b \rceil$($a\ge 0, b>0$)用代码可表示为(a + b - 1) / b
其中,$s_{k-1}$ 表示「位数不超过 $k-1$ 的自然数」的位数之和。
进一步,可以求出 $a_n$ 在 $x(n)$ 第几位。
比较方便的办法是,把个位作为第 0 位,十位作为第 1 位,百位作为第 2 位,以此类推;
这样,x 的第 j 位可以表示为 x / pow(10, j) % 10
设 $a_n$ 在 $x(n)$ 的第 $j$ 位,则有
$$ j = i k - (n +1 - s_{k-1}) $$

hihoCoder #1349 Nature Numbers的更多相关文章

  1. hihoCoder 1595 : Numbers

    Description You are given n constant integers c[1], c[2], ..., c[n] and an integer k. You are to ass ...

  2. hihoCoder 1432 : JiLi Number(吉利数)

    hihoCoder #1432 : JiLi Number(吉利数) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 Driver Ji l ...

  3. [HihoCoder] Highway 高速公路问题

    Description In the city, there is a one-way straight highway starts from the northern end, traverses ...

  4. The top 100 papers Nature explores the most-cited research of all time.

    The top 100 papers Nature explores the most-cited research of all time. The discovery of high-temper ...

  5. Project Euler:Problem 55 Lychrel numbers

    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...

  6. hihocoder 1873 ACM-ICPC北京赛区2018重现赛 D Frog and Portal

    http://hihocoder.com/problemset/problem/1873 时间限制:1000ms 单点时限:1000ms 内存限制:512MB 描述 A small frog want ...

  7. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  8. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  9. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

随机推荐

  1. self & this 上下文

    对象:指向对象的首地址: 函数:代表了函数运行的主要上下文: 内部:在类的内部使用. self Within the body of a class method, self refers to th ...

  2. OO第三次电梯作业优化

    目录 第三次电梯作业个人优化 前言 优化思路 一.调度器 二.电梯 第三次电梯作业个人优化 前言 由于个人能力有限,第二次电梯作业只能完成正确性设计,没能进行优化,也因此损失了强测分数,于是第三次电梯 ...

  3. oracle 数据导到 sql server

    方法一: navicate:用法比较简单,选择工具-数据传输就可以了.目前测试了下暂时没遇到什么问题. 方法二: Microsoft SQL Server Migration Assistant 8. ...

  4. DROP INDEX - 删除一个索引

    SYNOPSIS DROP INDEX name [, ...] [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP INDEX 从数据库中删除一个现存的索引. 要执 ...

  5. sql快速删除所用表,视图,存储过程

    [http://www.th7.cn/db/mssql/2011-07-07/10127.shtml#userconsent#] 删除用户表 .select 'DROP TABLE '+name fr ...

  6. Spring中使用事务搭建转账环境 转账操作,

    演示不使用事务出现异常情况 Dao层两个方法lessMoney()和moreMoney() package com.swift; import org.springframework.jdbc.cor ...

  7. c++调用系统关机命令 c++调用暂停命令

    #include<stdlib.h> int main() { //调用系统dos命令 system("shutdown -s -t 120"); ; } system ...

  8. iOS8之后,UITableViewRowAction实现滑动多个按钮

    #pragma mark - View lifeCycle - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = ...

  9. C# 用qq邮箱发邮件

    一.在企业的QQ邮箱中开启POP3/SMTP服务 开启服务时,授权密码保存好. 二.示例 public static string UserName = ""; // 企业邮箱 p ...

  10. 在Keras中导入测试数据的方法

    https://blog.csdn.net/ethantequila/article/details/80322425?utm_source=blogxgwz2