【题解】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 ...
随机推荐
- P1563 玩具谜题
P1563 玩具谜题 题目描述 小南有一套可爱的玩具小人, 它们各有不同的职业. 有一天, 这些玩具小人把小南的眼镜藏了起来. 小南发现玩具小人们围成了一个圈,它们有的面朝圈内,有的面朝圈外.如下图: ...
- 机器学习实战:决策树的存储读写文件报错(Python3)
错误原因:pickle模块存储的是二进制字节码,需要以二进制的方式进行读写 1. 报错一:TypeError: write() argument must be str, not bytes 将决策树 ...
- spring源码-Aware-3.4
一.Aware接口,这个也是spring的拓展之一,为啥要单独拿出来讲呢,因为他相比于BeanFactoryPostProcessor,BeanPostProcessor的实用性更加高,并且在具体的业 ...
- Jenkis 无法下载插件问题解决
在新机器上安装jenkins后,安装插件报如下错误 sun.security.provider.certpath.SunCertPathBuilderException: unable to find ...
- 适配iPhoneX、iPhoneXs、iPhoneXs Max、iPhoneXr 屏幕尺寸及安全区域
此篇文章是对上一篇文章(http://www.ifiero.com/index.php/archives/611)的进一步补充,主要说明如何适配Apple的最新三款手机iPhoneXs.iPhoneX ...
- JavaScript实现无刷新评论及在IE下的剪切板访问(学习)
1.无刷新评论 tips: appendChild:将新元素作为父元素的最后一个子元素进行添加. insertBefore:在一个指定的子节点之前插入一个节点 实现: <!DOCTYPE htm ...
- 1. 两数之和【Leetcode中国,by java】
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], target ...
- 【Random】-随机数字-jmeter
参数化 Random 参数化,存储结果的变量名,名字写了,就可以给其它请求使用
- JavaScript 之 对象/JSON/数组
对象 简单说,所谓对象,就是一种无序的数据集合,由若干个“键值对”(key-value)构成. var obj = { p: 'Hello World' }; 上面代码中,大括号就定义了一个对象,它被 ...
- Javascript闭包演示【转】
文章出自http://www.cnblogs.com/snandy/archive/2011/03/01/1967628.html 有个网友问了个问题,如下的html,为什么点击所有的段落p输出都是5 ...