hihoCoder #1349 Nature Numbers
题目大意
考虑自然数构成的序列 $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的更多相关文章
- hihoCoder 1595 : Numbers
Description You are given n constant integers c[1], c[2], ..., c[n] and an integer k. You are to ass ...
- hihoCoder 1432 : JiLi Number(吉利数)
hihoCoder #1432 : JiLi Number(吉利数) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 Driver Ji l ...
- [HihoCoder] Highway 高速公路问题
Description In the city, there is a one-way straight highway starts from the northern end, traverses ...
- 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 ...
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- hihocoder 1873 ACM-ICPC北京赛区2018重现赛 D Frog and Portal
http://hihocoder.com/problemset/problem/1873 时间限制:1000ms 单点时限:1000ms 内存限制:512MB 描述 A small frog want ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
随机推荐
- 如何通过修改文件添加用户到sudoers上
su - root chmod u+w /etc/sudoers (该文件没有写权限, 修改)vim /etc/sudoers 按下 I 键进行编写 # User privilege speci ...
- mysql5.7.24 解压版安装步骤以及遇到的问题
1.下载 https://dev.mysql.com/downloads/mysql/ 2.解压到固定位置,如D:\MySQL\mysql-5.7.24 3.添加my.ini文件 跟bin同级 [my ...
- CV做直方图的比较说明图形越相似性
#include "opencv/cv.hpp" #include "opencv2/objdetect/objdetect.hpp" #include &qu ...
- webpack开始一个项目的步骤
这几天在学习Vue 用到了webpack打包工具 开始一个项目的时候 需要配置很多项 刚开始写的时候 配置文件总是缺什么再去配置什么 创建项目就用了半个小时 后来觉得应该有个步骤 这样 ...
- Bootstrap 模态框 select2搜索框无法输入
去掉模态框的div中的 tabindex="-1" 这个属性 <div class="modal fade" role="dialog" ...
- 使用apache benchmark(ab) 测试报错: apr_socket_recv: Connection timed out (110)
使用ab( apache benchmark )测试的时候,使用如下命令: ab -n 15000 -c 200 http://localhost/abc/abc.php 执行操作一定条数,或连续 ...
- vue实现与安卓、IOS交互
方案背景 IOS用的是jsBridge插件实现调用.传参.回调的 安卓是在window挂载方法和挂载回调的 IOS实现方案 调用原生方法封装如下 function setupWebViewJavasc ...
- 【网络基础】【TCP/IP】私有IP地址段
私有IP地址段 Class A:10.0.0.0 - 10.255.255.255 Class B:172.16.0.0 - 172.31.255.255 Class C:192.168.0. ...
- 使用TensorFlow的卷积神经网络识别手写数字(2)-训练篇
import numpy as np import tensorflow as tf import matplotlib import matplotlib.pyplot as plt import ...
- 用decimal模块增加python的浮点数精度
浮点数python默认是17位精度,也就是小数点后16位(16位以后的全部四舍五入了),虽然有16位,但是这个精度越往后越不准. 如果有特殊需求,需要更多的精度,可以用decimal模块,通过更改其里 ...