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 ...
随机推荐
- BZOJ 4881: [Lydsy2017年5月月赛]线段游戏
4881: [Lydsy2017年5月月赛]线段游戏 Time Limit: 3 Sec Memory Limit: 256 MBSubmit: 164 Solved: 81[Submit][St ...
- 卓越管理的实践技巧(1)如何进行有效的指导 Guidelines for Effective Coaching
Guidelines for Effective Coaching 前文卓越管理的秘密(Behind Closed Doors)最后一部分提到了总结的13条卓越管理的实践技巧并列出了所有实践技巧名称的 ...
- windows自定义快速启动(运行)命令
自定义运行(windows键+R)里面命令,启动设置的程序,如图: 它的设置方法有两种: 第一种设置方法: 第1步:在任意地方创建一个文件夹(建议在D盘根目录创建),文件夹的名称可自定义没有特殊限制, ...
- JavaScript深入浅出第2课:函数是一等公民是什么意思呢?
摘要: 听起来很炫酷的一等公民是啥? <JavaScript深入浅出>系列: JavaScript深入浅出第1课:箭头函数中的this究竟是什么鬼? JavaScript深入浅出第2课:函 ...
- Manifest文件
Manifest文件是简单的文本文件,它告知浏览器缓存的内容(或不缓存的内容) Manifest文件可以分为三个部分: 1.CAHCEMANIFEST-在此标题下列出的文件将在首次下载后进行缓存. C ...
- linux文件或文件夹常见操作
创建文件夹 mkdir [-p] DirName 在工作目录下,建立一个名为 A 新的子目录 : mkdir A 在工作目录下的 B目录中,建立一个名为 T 的子目录: 若 B 目录不存在, ...
- cocos2dx 3.x lua 网络加载并且保存资源(unix、linux)
#ifndef __DazzleParkour__TextLoader__ #define __DazzleParkour__TextLoader__ #include <stdio.h> ...
- 设置通过Maven创建的工程的JDK的版本,更改conf/settings.xml
eclipse提示警告如下: Build path specifies execution environment J2SE-1.5. There are no JREs installed in t ...
- AES加密、解密工具类
AES加密.解密工具类代码如下: package com.util; import java.io.IOException; import java.io.UnsupportedEncodingExc ...
- vue + axios---封装一个http请求
在使用vue开发时,官方推荐使用axios来请求接口 // axios官方地址 https://github.com/axios/axios 但是axios并不像 vue-resource 一样拥有i ...