【题解】Atcoder ARC#90 F-Number of Digits
Atcoder刷不动的每日一题...
首先注意到一个事实:随着 \(l, r\) 的增大,\(f(r) - f(l)\) 会越来越小。考虑暴力处理出小数据的情况,我们可以发现对于左端点 \(f(l) <= 7\) 的情况下,右端点的最大限度为 \(\frac{10^8}{8} + 10^7\) 。这个范围并不大,可以直接用 two-pointer 处理出来。
那么这部分的数据和后面的数据有什么不同呢? 当 \(f(l) > 7\) 的时候,\(f(r) - f(l) <= 1\)。那么设 \(l = f(l)\),我们有:
\( x * l + y * (l + 1) = S \)
令 \( t = x + y \)
原式等于 \( t * l + y = S \);
我们令 \(x + y > y\) ,即 \( x != 0 \),那么最后一个式子实际上表达的是 \( y = S \ mod \ t \)。也就是说,对于任何的一个确定的 \(t\),(当 \(l\) 的范围 \(> 7\))我们都可以找到唯一对应的 \(x, y\) 与之对应。那么我们就可以扫一遍所有的 \(t\)以求得答案。注意当 \( y = 0 \) 时,对答案的贡献为这个数字范围内所有长为 \(t\) 的区间。
#include <bits/stdc++.h>
using namespace std;
#define maxn 23000000
#define int long long
#define mod 1000000007
int digit[maxn], ans, S; int read()
{
int x = , k = ;
char c; c = getchar();
while(c < '' || c > '') { if(c == '-') k = -; c = getchar(); }
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * k;
} int Qpow(int times)
{
int x = , base = ;
for(; times; times >>= , x = x * x % mod)
if(times & ) base = base * x % mod;
return base;
} void Up(int &x, int y) { x = (x + y) % mod; }
signed main()
{
S = read(); int lim = S / , now = ;
for(int i = ; i < maxn; i ++) digit[i] = digit[i / ] + ;
for(int i = , now = , tem = ; i < 1e7; i ++)
{
while(tem < S) { tem += digit[now]; now ++; }
if(tem == S) { ans += ; if(ans >= mod) ans -= mod; }
tem -= digit[i];
}
for(int i = ; i <= lim; i ++)
{
if(!(S % i))
{
int l = S / i, sum = Qpow(l - ) * % mod;
Up(ans, (sum - i + + mod) % mod);
}
else
{
int l = (S - S % i) / i;
ans += ; if(ans >= mod) ans -= mod;
}
}
printf("%lld\n", ans);
return ;
}
【题解】Atcoder ARC#90 F-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 ...
- 【题解】 AtCoder ARC 076 F - Exhausted? (霍尔定理+线段树)
题面 题目大意: 给你\(m\)张椅子,排成一行,告诉你\(n\)个人,每个人可以坐的座位为\([1,l]\bigcup[r,m]\),为了让所有人坐下,问至少还要加多少张椅子. Solution: ...
- 【题解】Atcoder ARC#90 E-Avoiding Collision
自己做出来固然开心,但是越发感觉到自己写题的确是很慢很慢了……往往有很多的细节反反复复的考虑才能确定,还要加油呀~ 这道题目的突破口在于正难则反.直接求有多少不相交的不好求,我们转而求出所有相交的.我 ...
- [题解] Atcoder ARC 142 D Deterministic Placing 结论,DP
题目 (可能有点长,但是请耐心看完,个人认为比官方题解好懂:P) 首先需要注意,对于任意节点i上的一个棋子,如果在一种走法中它走到了节点j,另一种走法中它走到了节点k,那么这两种走法进行完后,棋子占据 ...
- [题解] Atcoder ARC 142 E Pairing Wizards 最小割
题目 建图很妙,不会. 考虑每一对要求合法的巫师(x,y),他们两个的\(a\)必须都大于\(min(b_x,b_y)\).所以在输入的时候,如果\(a_x\)或者\(a_y\)小于\(min(b_x ...
- [题解] Atcoder AGC 005 F Many Easy Problems NTT,组合数学
题目 观察当k固定时答案是什么.先假设每个节点对答案的贡献都是\(\binom{n}{k}\),然后再减掉某个点没有贡献的选点方案数.对于一个节点i,它没有贡献的方案数显然就是所有k个节点都选在i连出 ...
- [atcoder contest 010] F - Tree Game
[atcoder contest 010] F - Tree Game Time limit : 2sec / Memory limit : 256MB Score : 1600 points Pro ...
- 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 ...
随机推荐
- 基于套接字通信的简单练习(FTP)
本项目基于c/s架构开发(采用套接字通信,使用TCP协议) FTP-Socket"""__author:rianley cheng""" 功 ...
- Ruby 基础教程 1-2
1.数组 创建 arrayname=[] arrayname=["1",12,"23"] 访问 arrayname[index] 更新 arrayname[in ...
- `Facebook.Unity.Settings' has already been imported error solution
after import facebook sdk to unity, i get the '`Facebook.Unity.Settings' has already been imported' ...
- 一种精准monkey测试的方法
WeTest 导读 相信大家都知道移动端应用的monkey测试吧,不知你们有没有为monkey测试的太过于随机性的特性有过困扰,至少在我们这种界面控件较少且控件位置较偏的app的使用上其测试有效性大打 ...
- Matlab R2016a 破解教程
郑重声明:图片来源于网络,在这里感谢图片提供者,我写这篇教程,是希望帮助后来者少走弯路,而且,这是一种比较简单有效的破解方法,针对网上那种修改本地文件的方法,在这里不做介绍,如果想体验,可自己百度或谷 ...
- 韦大仙--Katalon---一款好用的selenium自动化测试插件
selenium框架是目前使用较广泛的开源自动化框架,一款好的.基于界面的录制工具对于初学者来说可以快速入门:对于老手来说可以提高开发自动化脚本的效率.我们知道Selenium IDE是一款使用较多的 ...
- List和String数组相互转化
在工作中经常会遇到需要String[] 参数的地方,我们可以先定义一个list,再转成String[] 来使用,使用list的好处自然是可以随时方便的添加删除元素,下面是方法: List list = ...
- python 终极篇 --- form组件 与 modelForm
form组件 ...
- 数据库Mysql的学习(六)-子查询和多表操作
)*0.05 WHERE card_id ='20121xxxxxx'; //子查询就是一个嵌套先计算子查询 SELECT * FROM borrow WHERE book_id =(SELECT b ...
- Wordcount -- MapReduce example -- Reducer
Reducer receives (key, values) pairs and aggregate values to a desired format, then write produced ( ...