首页 技术 正文
技术 2022年11月18日
0 收藏 333 点赞 4,674 浏览 1015 个字

  1. ★☆ 输入文件:eight.in 输出文件:eight.out 简单对比

    时间限制:1 s 内存限制:128 MB

    【问题描述】

    八是个很有趣的数字啊。八=发,八八=爸爸,88=拜拜。当然最有趣的还是8用二进制表示是1000。怎么样,有趣吧。当然题目和这些都没有关系。

    某个人很无聊,他想找出[a,b]中能被8整除却不能被其他一些数整除的数。

    【输入文件】

    第一行一个数n,代表不能被整除的数的个数。第二行n个数,中间用空格隔开。第三行两个数a,b,中间一个空格。

    【输出文件】

    一个整数,为[a,b]间能被8整除却不能被那n个数整除的数的个数。

    【样例输入】

    eight.in

    3

    7764 6082 462

    2166 53442

    【样例输出】

    eight.out

    6378

    【数据规模】

    对于30%的数据, 1≤n≤5,1≤a≤b≤100000。

    对于100%的数据,1≤n≤15,1≤a≤b≤10^9,N个数全都小于等于10^4大于等于1。

/*
一道容斥一眼题.
全集就是[l,r]中8的倍数的个数了.
考虑不合法的部分就是8的其他数的LCM了
n这么小 二进制拆分一下枚举子集就好了.
*/
#include<iostream>
#include<cstdio>
#define MAXN 20
#define LL long long
using namespace std;
LL n,a[MAXN],l,r,ans,tot,Lcm;
LL gcd(LL a,LL b)
{
if(!b) return a;
return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
return a*b/gcd(a,b);
}
void slove()
{
ans=r/8-(l-1)/8;
for(int s=1;s<=(1<<n)-1;s++)
{
tot=0;Lcm=8;
for(int i=0;i<n;i++)
if(s&(1<<i)) tot++,Lcm=lcm(Lcm,a[i]);
if(tot&1) ans-=r/Lcm-(l-1)/Lcm;
else ans+=r/Lcm-(l-1)/Lcm;
}
}
int main()
{
freopen("eight.in","r",stdin);
freopen("eight.out","w",stdout);
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
scanf("%d %d",&l,&r);
slove();
printf("%d",ans);
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848