标签:数学公式 else 理论 scanf out ++ 自己 复杂 include
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout) #define maxn 10010 using namespace std; typedef long long llg; int la,lb,ci; llg now,ans,mi[15],l,r; llg a[maxn],b[maxn]; void search(int d){ if(now>r) return; llg xx=now; now=xx+6*mi[d]; search(d+1); now=xx+8*mi[d]; search(d+1); if(xx) a[++la]=xx; now=xx; } llg gcd(llg a,llg b){ llg r=a%b; while(r) a=b,b=r,r=a%b; return b; } void dfs(int j){ if(j==lb+1){ if(!ci) return; if(ci&1) ans+=r/now-(l-1)/now; else ans-=r/now-(l-1)/now; return; } dfs(j+1); llg xx=now; ci++; now=xx/gcd(xx,b[j]); if((double)now*b[j]<=r){ now*=b[j]; if(now<=r) dfs(j+1); } ci--; now=xx; } int main(){ File("a"); mi[0]=1; for(int i=1;i<=10;i++) mi[i]=mi[i-1]*10; scanf("%lld %lld",&l,&r); search(0); sort(a+1,a+la+1); for(int i=1;i<=la;i++){ b[++lb]=a[i]; for(int j=1;j<lb;j++) if(a[i]%b[j]==0){lb--; break;} } for(int i=1;i<=lb/2;i++) swap(b[i],b[lb-i+1]); now=1; dfs(1); printf("%lld",ans); return 0; }
标签:数学公式 else 理论 scanf out ++ 自己 复杂 include
原文地址:http://www.cnblogs.com/lcf-2000/p/6217894.html