「SCOI2010」幸运数字
传送门
Luogu
解题思路
首先构造出所有的幸运数字。
然后考虑一个幸运数字会产生多少贡献。
对于一个数 \(x\),它在区间 \([l,r]\) 内的倍数的个数为 \(\lfloor \frac{r}{x} \rfloor - \lceil \frac{l}{x} \rceil + 1\)。
那么我们就只需要对每一个幸运数字算一次贡献即可。。。。。???
然而答案是否定的。
因为同一个数可能是多个幸运数字的倍数,所以我们就需要容斥这些幸运数字的lcm,同理在之前要去掉是其他幸运数字倍数的幸运数字,这样就好了。
细节注意事项
- 注意一下这题可能会有一些炸数据范围的情况,
long double了解一下。
参考代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define int long long
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
}
const int LIM = 10000000000;
const int _ = 100002;
int n, vis[_], luck[_], l, r, ans;
inline void dfs1(int x) {
if (x > LIM) return ;
if (x != 0) luck[++n] = x;
dfs1(x * 10 + 6), dfs1(x * 10 + 8);
}
inline void init() {
dfs1(0);
sort(luck + 1, luck + n + 1);
for (rg int i = 1; i <= n; ++i)
for (rg int j = i + 1; j <= n; ++j)
if (luck[j] % luck[i] == 0) vis[j] = 1;
int tmp = 0;
for (rg int i = 1; i <= n; ++i)
if (!vis[i]) luck[++tmp] = luck[i];
n = tmp;
sort(luck + 1, luck + n + 1, greater < int > ());
}
inline int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; }
inline int f(int x) { return r / x - (l / x + (l % x != 0 ? 1 : 0)) + 1; }
inline void dfs(int x, int cnt, int Lcm) {
if (x == n + 1) {
if (Lcm != 1) ans += (cnt % 2 == 1 ? 1 : -1) * f(Lcm); return ;
}
dfs(x + 1, cnt, Lcm);
long double _Lcm = 1.0 * Lcm / gcd(Lcm, luck[x]) * luck[x];
if (_Lcm > r) return ;
dfs(x + 1, cnt + 1, _Lcm);
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
init();
read(l), read(r);
dfs(1, 0, 1);
printf("%lld\n", ans);
return 0;
}
完结撒花 \(qwq\)
「SCOI2010」幸运数字的更多相关文章
- loj#2013. 「SCOI2016」幸运数字 点分治/线性基
题目链接 loj#2013. 「SCOI2016」幸运数字 题解 和树上路径有管...点分治吧 把询问挂到点上 求出重心后,求出重心到每个点路径上的数的线性基 对于重心为lca的合并寻味,否则标记下传 ...
- AC日记——「SCOI2016」幸运数字 LiBreOJ 2013
「SCOI2016」幸运数字 思路: 线性基: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 20005 # ...
- loj #2013. 「SCOI2016」幸运数字
#2013. 「SCOI2016」幸运数字 题目描述 A 国共有 n nn 座城市,这些城市由 n−1 n - 1n−1 条道路相连,使得任意两座城市可以互达,且路径唯一.每座城市都有一个幸运数字,以 ...
- 「洛谷3292」「BZOJ4568」「SCOI2016」幸运数字【倍增LCA+线性基+合并】
[bzoj数据下载地址]不要谢我 先讲一下窝是怎么错的... \(MLE\)是因为数组开小了.. 看到异或和最大,那么就会想到用线性基. 如果不会线性基的可以参考一下我的学习笔记:「线性基」学习笔记a ...
- LOJ #2013「SCOI2016」幸运数字
时限为什么这么大啊 明摆着放多$ log$的做法过啊$QAQ$ LOJ #2013 题意 有$ Q$次询问,每次询问树上一条链,点有点权,你需要选择一些链上的点使得异或和尽量大 点数$ \leq 2* ...
- 【LOJ】 #2013. 「SCOI2016」幸运数字
题解 最大异或和,明显是个线性基 然而还有那么多路径--那就树分治,反正点数看起来很少,就是为了让人乘上一个60的常数嘛 把一个树的点分树记录下来,然后看看询问的两个点彼此相同的最后一个父亲是谁,把这 ...
- loj2013 「SCOI2016」幸运数字
点分治+线性基 (为了这六个字窝调了一下午一晚上QAQ #include <iostream> #include <cstring> #include <cstdio&g ...
- BZOJ 1853 【Scoi2010】 幸运数字
Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认 为,于是他定义自己的"幸运号码"是十进制表示中只包含数字6和8的那些号码,比如68,666,8 ...
- 「转」python数字图像处理(18):高级形态学处理
python数字图像处理(18):高级形态学处理 形态学处理,除了最基本的膨胀.腐蚀.开/闭运算.黑/白帽处理外,还有一些更高级的运用,如凸包,连通区域标记,删除小块区域等. 1.凸包 凸包是指一 ...
随机推荐
- 创业学习---今日头条创业过程分析---HHR计划
本文搜集和整理了今日头条创业的一些关键点的资料------by 春跃(本文的主要观点都是搜集整理,所以不得本人同意不得转载) 一,18年之前的今日头条创业时间表: 1,张一鸣参与创业的履历:酷讯,饭否 ...
- Mobility Express部署外部镜像服务器
1.当我们部署完ME的时候,发现有一些AP虽然显示已经加入了WLC(ME),但是它其实并没有正常的工作,显示不可用: (Cisco Controller) >show ap su Number ...
- codeforces- Shortest path of the king
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...
- text-align:justify 失效问题。
text-align:justify 失效问题. <div class="fmlist_left"> <p> <span> 品名 <i c ...
- 记一次RocketMQ源码导入IDEA过程
首先,下载源码,可以官网下载source包,也可以从GitHub上直接拉下来导入IDEA.如果是官网下载的source zip包,直接作为当前project的module导入,这里不赘述太多,只强调一 ...
- 腾讯云 docker 镜像 dotnet/core sdk aspnet
ccr.ccs.tencentyun.com/mcr.microsoft.com/dotnetcoresdk = mcr.microsoft.com/dotnet/core/sdk => 3 ...
- selenium webdriver 屏幕滚动
//山寨法 String setscroll = "document.documentElement.scrollTop=100"; JavascriptExecutor jse= ...
- flask view
flask view 1. flask view 1.1. @route 写个验证用户登录的装饰器:在调用函数前,先检查session里有没有用户 from functools imp ...
- java事务/springboot事务/redis事务
java事务(数据库事务):jdbc事务--ACID springboot事务:@Transactional--ACID redis事务:命令集合 将redis事务与mysql事务对比: Mysq ...
- Atom 必装插件
Atom 必装插件 转载请注明出处. https://blog.csdn.net/Nick_php/article/details/54020956 主题 atom-material-ui 字体配色 ...