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的更多相关文章

  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. 【题解】 AtCoder ARC 076 F - Exhausted? (霍尔定理+线段树)

    题面 题目大意: 给你\(m\)张椅子,排成一行,告诉你\(n\)个人,每个人可以坐的座位为\([1,l]\bigcup[r,m]\),为了让所有人坐下,问至少还要加多少张椅子. Solution: ...

  3. 【题解】Atcoder ARC#90 E-Avoiding Collision

    自己做出来固然开心,但是越发感觉到自己写题的确是很慢很慢了……往往有很多的细节反反复复的考虑才能确定,还要加油呀~ 这道题目的突破口在于正难则反.直接求有多少不相交的不好求,我们转而求出所有相交的.我 ...

  4. [题解] Atcoder ARC 142 D Deterministic Placing 结论,DP

    题目 (可能有点长,但是请耐心看完,个人认为比官方题解好懂:P) 首先需要注意,对于任意节点i上的一个棋子,如果在一种走法中它走到了节点j,另一种走法中它走到了节点k,那么这两种走法进行完后,棋子占据 ...

  5. [题解] Atcoder ARC 142 E Pairing Wizards 最小割

    题目 建图很妙,不会. 考虑每一对要求合法的巫师(x,y),他们两个的\(a\)必须都大于\(min(b_x,b_y)\).所以在输入的时候,如果\(a_x\)或者\(a_y\)小于\(min(b_x ...

  6. [题解] Atcoder AGC 005 F Many Easy Problems NTT,组合数学

    题目 观察当k固定时答案是什么.先假设每个节点对答案的贡献都是\(\binom{n}{k}\),然后再减掉某个点没有贡献的选点方案数.对于一个节点i,它没有贡献的方案数显然就是所有k个节点都选在i连出 ...

  7. [atcoder contest 010] F - Tree Game

    [atcoder contest 010] F - Tree Game Time limit : 2sec / Memory limit : 256MB Score : 1600 points Pro ...

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

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

随机推荐

  1. 【Keras案例学习】 CNN做手写字符分类(mnist_cnn )

    from __future__ import print_function import numpy as np np.random.seed(1337) from keras.datasets im ...

  2. ORB-SLAM(十)LoopClosing

    构造函数 LoopClosing(Map* pMap, KeyFrameDatabase* pDB, ORBVocabulary* pVoc,const bool bFixScale); 主要分两部分 ...

  3. oracle 建立一个视图,然后授权其他用户访问

    grant select on V_LIC_ENTRY_HZ_STATUS to ielicr2013; create or replace view dept_sum_vw (name,minsal ...

  4. 「日常训练」 Genghis Khan the Conqueror(HDU-4126)

    题意 给定\(n\)个点和\(m\)条无向边(\(n\le 3000\)),需要将这\(n\)个点连通.但是有\(Q\)次(\(Q\le 10^4\))等概率的破坏,每次破坏会把\(m\)条边中的某条 ...

  5. JVM常见配置

    堆设置 -Xms:初始堆大小 -Xmx:最大堆大小 -XX:NewSize=n:设置年轻代大小 -XX:NewRatio=n:设置年轻代和年老代的比值.如:为3,表示年轻代与年老代比值为1:3,年轻代 ...

  6. 初学Direct X (2)

    初学Direct X (2) 这一次要学习如何现实位图,尽管看过对双缓冲机制还有很多疑问,但是这并不阻碍我对他的入门了解 Direct3D提供了一个双重/后台缓冲区,在调用CreateDevice之时 ...

  7. OIDC in Angular 6

    参照 草根专栏- ASP.NET Core + Ng6 实战:https://v.qq.com/x/page/i07702h18nz.html 1. OIDC-Client https://githu ...

  8. vue-router爬坑记

    简介 因为我们用Vue开发的页面是单页面应用,就相当于只有一个主的index.html,这时候我们就不能使用a标签来进行页面的切换了,所以这时候我们今天的主角Vue-Router就闪亮的登场了 Vue ...

  9. lintcode100 删除排序数组中的重复数字

    删除排序数组中的重复数字   给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度. 不要使用额外的数组空间,必须在原地没有额外空间的条件下完成. 您在真实的 ...

  10. 【springmvc+mybatis项目实战】杰信商贸-4.maven依赖+PO对+映射文件

    上一篇我们附件的增删改查功能全部完成.但是我们的附件有一个字段叫做“类型”(ctype),这里我们要使用数据字典,所以对于这一块我们要进行修改. 首先介绍一下数据字典 数据字典它是一个通用结构,跟业务 ...