dfs version inclusion and exclusion + pruning --bzoj1853

A blast search Science Edition + pruning inclusion-exclusion method, i.e., by dp Similarly digit bit repellent capacity, while the need to prune the search process

/*
Inclusion and exclusion, the first screen in the hit list out all the multiples, then the principle of inclusion and exclusion of multiple +1 -2 +3 multiples lcm lcm of multiple ...
Note that pruning is determined to prevent the explosion Long Long 
 * / 
#include <bits / STDC ++ H.>
 The using  namespace STD;
 #define LL Long Long 
 #define MAXN 200005
ll l,r,ans;
ll a[maxn],m,b[maxn],n;
void init(ll x){
    if(x>r)return;
    a[++m]=x;
    init(x*10+6);
    init(x*10+8); 
}

void dfs(int pos,int num,ll now){
    if(pos>n){
        if(num%2)
            ans+=r/now-(l-1)/now;
        else if(num)ans-=r/now-(l-1)/now;
        return;
    }
    dfs(pos+1,num,now);//不取第pos位
    ll tmp=now/__gcd(b[pos],now);//防止爆ll 
    if((double)b[pos]*tmp<=(double)r)
        dfs(pos+1,num+1,b[pos]*tmp); 
}

int screws [maxn];
int main () {
    cin>>l>>r;
    Heating ( 6 ), heat ( 8 );
    Sort (A + . 1 , A + . 1 + m); // arranged in an ordered sequence
    
    for(int i=1;i<=m;i++)
        if(vis[i]==0){
            for(int j=i+1;j<=m;j++)
                if(a[j]%a[i]==0)
                    am [j] = 1 ;
        }
    for(int i=m;i>=1;i--)
        if(!vis[i])b[++n]=a[i];
    dfs(1,0,1);
    cout<<ans<<endl;
}

 

Guess you like

Origin www.cnblogs.com/zsben991126/p/11146055.html