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)\) 会越小。

分两种情况讨论:

  1. \(f(l)\leq 7\) ,这时可以用尺取法来做,可以发现它的右界为 \(10^7+\frac{10^8}{8}=22500000\) ;

  2. \(f(l)\geq 8\) ,我们依旧可以分两种情况来考虑:

    1. \(f(r)-f(l)=0\) ,此时显然选的数都是位数相同的,我们可以统计这种位数的个数 \(sum\) ,该种情况的答案 \(sum-f(l)+1\) ;

    2. \(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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 【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 ...

  4. AtCoder Beginner Contest 057 ABCD题

    A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...

  5. codeforces Hill Number 数位dp

    http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits: ...

  6. 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 ...

  7. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

  8. ACdream 1188 Read Phone Number (字符串大模拟)

    Read Phone Number Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Sub ...

  9. hdu 1018:Big Number(水题)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. 根据IO流源码深入理解装饰设计模式使用

    一:摘要 通过对java的IO类中我们可以得出:IO源码中使用装饰设计模式频率非常高, 对装饰设计模式而言,他能够避免继承体系的臃肿,同时也可以动态的给一个对象添加一些额外的功能,如果要扩展一个功能, ...

  2. js中的类型转换

    先介绍一下 typeof 的使用方法: typeof(mix)   或者  typeof  mix 其中 mix 可以是任何数据类型 typeof 的返回值有六种:number.string.bool ...

  3. RTMP消息详细介绍

    本文继上篇简单分析了RTMP协议如何进行通信进一步详细分析RTMP的消息都有哪些,以及这些消息有什么作用. 一.RMTP消息 由上一篇文章可知RTMP 消息有分成两个部分,一个是头部,一个是有效负载. ...

  4. Mysql 相关操作

    1.用户管理 创建用户 create user '用户名'@'IP地址' identified by '密码'; 删除用户 drop user '用户名'@'IP地址'; 修改用户 rename us ...

  5. NOIP2016 天天爱跑步 正解

    暴力移步 http://www.cnblogs.com/TheRoadToTheGold/p/6673430.html 首先解决本题应用的知识点: dfs序——将求子树的信息(树形)转化为求一段连续区 ...

  6. IE浏览器支持响应式网站设计

    目前响应式网站设计比较流行, 下面是摘自百度百科有关响应式设计的定义. 响应式网站设计是一种网络页面设计布局,其理念是:集中创建页面的图片排版大小,可以智能地根据用户行为以及使用的设备环境进行相对应的 ...

  7. Python脚本自动提取和替换代码中的中文

    # -*- coding: utf-8 -*- import os import os.path import re import sys reload(sys) sys.setdefaultenco ...

  8. JAVA_SE基础——70.Math类

    package cn.itcast.other; /*  Math 数学类, 主要是提供了很多的数学公式.    abs(double a)  获取绝对值  ceil(double a)  向上取整 ...

  9. 彻底搞懂shell的高级I/O重定向

    本文目录: 1.1 文件描述符(file description,fd) 1.2 文件描述符的复制 1.3 重定向顺序很重要:">file 2>&1"和&quo ...

  10. 使用IDEA快速插入数据库数据的方法

    如上图所示:数据库创建表主键使用了自增列自增因此忽略,只有后两列非主键得数据,在数据较多得时候使用IDEA快捷键Ctrl+R键,快速查找替换.