题目

P2567 [SCOI2010]幸运数字

做法

容斥+剪枝

先预处理幸运数字,别看数据范围这么大,其实也没几个,然后去掉倍数这种

然后处理相似数字,一眼的容斥,递归选数然后求出这些的公倍数容斥一下

玄学剪枝:从大到小排列,若公倍数大于范围退出,加速大于范围的情况

My complete code

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<ctime>
using namespace std;
typedef long long LL;
const int maxn=100000;
LL A,B;
int tot,cnt,ans;
LL a[maxn],num[maxn];
bool visit[maxn];
void First(int dep,int now,LL bit,LL x){
if(now>dep){
a[++tot]=bit;
return;
}
First(dep,now+1,bit+(x<<2)+(x<<1),(x<<3)+(x<<1)),
First(dep,now+1,bit+(x<<3),(x<<3)+(x<<1));
}
inline bool cmp(LL x,LL y){
return x>y;
}
inline LL Gcd(LL a,LL b){
while(b){
LL c=a%b;
a=b,b=c;
}
return a;
}
inline LL Calc(LL l,LL r,LL lcm){
return r/lcm-(l-1)/lcm;
}
void Dfs(int dep,int now,LL val){
if(val>B)
return;
if(dep>cnt){
if(now==0)
return;
ans+=Calc(A,B,val)*((now&1)?1:-1);
return;
}
Dfs(dep+1,now,val);
LL lcm=val/Gcd(val,num[dep]);
if(1.0*lcm*num[dep]<=B)
Dfs(dep+1,now+1,lcm*num[dep]);
}
int main(){
scanf("%lld%lld",&A,&B);
int t1=clock();
for(int i=1;i<=10;++i)
First(i,1,0,1);//printf("233");
for(int i=1;i<=tot;++i){
if(!visit[i])
num[++cnt]=a[i];
for(int j=i+1;j<=tot;++j)
if(a[j]%a[i]==0)
visit[j]=true;
}
sort(num+1,num+1+cnt,cmp);
Dfs(1,0,1ll);
printf("%lld\n",ans);
return 0;
}/*
1 10000000000
*/

P2567 [SCOI2010]幸运数字的更多相关文章

  1. P2567 [SCOI2010]幸运数字 DFS+容斥定理

    P2567 [SCOI2010]幸运数字 题目描述 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,66 ...

  2. Luogu P2567 [SCOI2010]幸运数字 容斥+脑子

    双倍经验:BZOJ 2393 Cirno的完美算数教室 做法:先把$[1,r]$中所有的幸运数字筛出来,然后用这些幸运数字来筛$[l,r]$中的近似幸运号码: 剪枝:当一个幸运数字$a[i]$是另一个 ...

  3. [洛谷P2567] SCOI2010 幸运数字

    问题描述 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的"幸运号码"是十进制表示中只包含数字6和8的那些号码,比如68,666,888都是&quo ...

  4. BZOJ 1853: [Scoi2010]幸运数字

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 2117  Solved: 779[Submit][Status] ...

  5. Bzoj 1853: [Scoi2010]幸运数字 容斥原理,深搜

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1774  Solved: 644[Submit][Status] ...

  6. bzoj 1853: [Scoi2010]幸运数字 容斥

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1170  Solved: 406[Submit][Status] ...

  7. bzoj1853[Scoi2010]幸运数字 容斥

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 3027  Solved: 1128[Submit][Status ...

  8. BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理

    BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理 题意: ~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种 ...

  9. 【BZOJ 1853】 1853: [Scoi2010]幸运数字 (容斥原理)

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 2472  Solved: 911 Description 在中国 ...

随机推荐

  1. CSS 选择器 :last-child与:last-of-type的区别

    :last-child----represents the last element among a group of sibling elements. CSS伪类 :last-child 代表在一 ...

  2. CentOS7 yum 安装 Nginx最新版本

    CentOS7 yum 安装 Nginx最新版本 下载对应当前系统版本的nginx包(package) # wget  http://nginx.org/packages/centos/7/noarc ...

  3. oracle中创建dblink

    create database link to_group connect to UCR_GROUP identified by "UCR_GROUPQWER"using '(de ...

  4. UVA 10209

    10209 - Is This Integration ? #include <stdio.h> #include <math.h> /* */ //多次错误都是因为我将PI定 ...

  5. myeclipse配置问题

    一,配置相关 1,myeclipse配置jdk Window --> Preferences --> Java --> Installed JREs 2.myeclipse配置tom ...

  6. CardView的具体使用方法(转)

    转载自:CardView的具体使用方法  因为学习做此记录方便查找使用 今天主要是CardView的用法,CardView是在安卓5.0提出的卡片式控件.首先介绍一下它的配置. 在gradle文件下添 ...

  7. 使用Office 365前,企业必须要知道的10件事

    目前的市场上充斥着很多关于微软Office 365的炒作,相信厂商.客户或者企业的都有自己不同的考虑.Office 365是微软云版本的Office,用户可以通过互联网创建一个帐户,付款.下载应用安装 ...

  8. Downloading jQuery

    Compressed and uncompressed copies of jQuery files are available. The uncompressed file is best used ...

  9. STM32 Option Bytes位 重置为出厂设置

    STM32 Option Bytes位 重置为出厂设置 JLINK 按照说明,在IAR安装目录下找到指定的运行程序JLinkSTM32.exe(D:\Program Files (x86)\IAR S ...

  10. Java线程面试题:设计四个线程,其中两个线程每次对 j 加 1,另外两个每次对 j 减 1,程序如下。

    package thread; /** * Java线程面试题 * @author zhongfg * @date 2015-06-16 */ public class ThreadInterview ...