[AtCoder arc090F]Number of Digits
Description
记 \(d\) 在十进制下的位数为 \(f(d)\) 。给出询问 \(S\) ,求有多少对 \((l,r)\) 使得 \[\sum_{i=l}^r f(i)=S\]
\(1\leq S\leq 10^8\)
Solution
颓了题解...
注意到当数字越大时 \(f(r)-f(l)\) 会越小。
分两种情况讨论:
\(f(l)\leq 7\) ,这时可以用尺取法来做,可以发现它的右界为 \(10^7+\frac{10^8}{8}=22500000\) ;
\(f(l)\geq 8\) ,我们依旧可以分两种情况来考虑:
\(f(r)-f(l)=0\) ,此时显然选的数都是位数相同的,我们可以统计这种位数的个数 \(sum\) ,该种情况的答案 \(sum-f(l)+1\) ;
\(f(r)-f(l)=1\) 。假设取的数个数为 \(t\) ,即 \(r-l+1=t\) ,取长度为 \(f(l)\) 的个数为 \(x\) ,长度为 \(f(r)\) 的个数为 \(y\) : \[\begin{cases}x+y=t\\x\cdot f(l)+y\cdot f(r)=S\end{cases}\]
那么 \(f(l)\cdot t+y=S\) 我们可以枚举 \(t\) ,容易发现 \(\begin{cases}y=S~mod~t\\x=t-S~mod~t\end{cases}\) ,即对于每个 \(t\) ,都可以解出唯一解。值得注意的是这方面的解会和上面的解重复,即当 \(f(l)\mid S\) 这里会计算一次。
综上可以分情况处理。
Code
//It is made by Awson on 2018.2.3
#include <bits/stdc++.h>
#define LL long long
#define dob complex<double>
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
#define writeln(x) (write(x), putchar('\n'))
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int l1 = 10000000;
const int l2 = 25500000;
const int yzh = 1e9+7;
void read(int &x) {
char ch; bool flag = 0;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
x *= 1-2*flag;
}
void print(int x) {if (x > 9) print(x/10); putchar(x%10+48); }
void write(int x) {if (x < 0) putchar('-'); print(Abs(x)); }
int s, f[l2+5];
int quick_pow(int a, int b) {
int ans = 1;
while (b) {
if (b&1) ans = 1ll*ans*a%yzh;
a = 1ll*a*a%yzh, b >>= 1;
}
return ans;
}
int count1(int n) {
int ans = 0, r = 0, cnt = 0;
for (int i = 1; i < l1; i++) {
cnt -= f[i-1];
while (cnt+f[r+1] <= s && r < l2) cnt += f[++r];
if (cnt == s) ++ans;
if (r == l2) break;
}
return ans;
}
int count2(int n) {
int lim = n/8, ans = lim;
for (int t = 1; t <= lim; t++)
if (n%t == 0) {
int len = n/t;
(ans += (1ll*quick_pow(10, len-1)*9%yzh-t)%yzh) %= yzh;
}
return ans;
}
void work() {
for (int i = 1, r = 10, cnt = 1; i < l1; i++, i = r, r = r*10, cnt++)
for (int j = i; j < r; j++) f[j] = cnt;
for (int i = l1; i <= l2; i++) f[i] = 8;
read(s);
writeln(((count1(s)+count2(s))%yzh+yzh)%yzh);
}
int main() {
work();
return 0;
}
[AtCoder arc090F]Number of Digits的更多相关文章
- AtCoder Regular Contest 090 F - Number of Digits
题目链接 Description For a positive integer \(n\), let us define \(f(n)\) as the number of digits in bas ...
- Find the smallest number whose digits multiply to a given number n
Given a number ‘n’, find the smallest number ‘p’ such that if we multiply all digits of ‘p’, we get ...
- 【leetcode】1295. Find Numbers with Even Number of Digits
题目如下: Given an array nums of integers, return how many of them contain an even number of digits. Exa ...
- AtCoder Beginner Contest 057 ABCD题
A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest E. Equal Digits
E. Equal Digits time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- ACdream 1188 Read Phone Number (字符串大模拟)
Read Phone Number Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Sub ...
- hdu 1018:Big Number(水题)
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- Java 并发基础——线程安全性
当线程安全:多个线程访问某个类时,不管运行时环境采用何种调度方式或者这些线程将如何交替执行,并且在主调代码中不需要任何额外的同步或协调,这个类都能表现出正确的行为,那么久称这个类是线程安全的. 在线程 ...
- Django—urls系统:urls基础
Django的urls系统简介 Django 1.11版本 URLConf官方文档 URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映 ...
- C作业--数据类型
一.PTA实验作业 题目1:7-3 倒顺数字串 1. 本题PTA提交列表 2. 设计思路(伪代码) (1)本题是要求输入倒顺序数串,首先看到这种题肯定是需要用到循环,那就先定一个整形i来进行循环,n是 ...
- JAVA接口基础知识总结
1:是用关键字interface定义的. 2:接口中包含的成员,最常见的有全局常量.抽象方法. 注意:接口中的成员都有固定的修饰符. 成员变量:public static final 成员方法 ...
- centos 安装配置 mysql
安装环境:CentOS7 64位 MINI版,安装MySQL5.7 1.配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo ...
- recompose mapProps
mapProps介绍 mapProps函数接收一个函数参数,这个函数参数会返回一个对象用作为接下来的组件的props.组件接收到的props只能是通过mapProps函数参数返回的对象,其他的prop ...
- [Redis源码阅读]redis持久化
作为web开发的一员,相信大家的面试经历里少不了会遇到这个问题:redis是怎么做持久化的? 不急着给出答案,先停下来思考一下,然后再看看下面的介绍.希望看了这边文章后,你能够回答这个问题. 为什么需 ...
- $.each遍历json数组
1.遍历单层json数组 我们把idx和obj都打印出来看看,到底是什么东西 var json1 =[{"id":"1","tagName" ...
- angular2 学习笔记 ( unit test 单元测试 )
第一次写单元测试. 以前一直都有听说 TDD 的事情. 今天总算是去尝试了一下. 先说说 TDD 的想法, 是这样的, 开发项目的流程 : 确定需求 -> 写类,接口,方法的名字(不写具体实现代 ...
- zuul入门(2)zuul的过滤器分类和加载
一.Groovy编写的Filter 1.可以放到指定目录加载 创建一个pre类型的filter,在run方法中获取HttpServletRequest 然后答应header信息 在代码中加入groov ...