容斥原理
虽然只含6、8的数有很多
但是题解告诉我真正互质的只有10+个woc
然后容斥原理,注意爆long long ,用double 近似比较
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<string> 7 #include<cmath> 8 #include<ctime> 9 #include<queue> 10 #include<stack> 11 #include<map> 12 #include<set> 13 #define rre(i,r,l) for(int i=(r);i>=(l);i--) 14 #define re(i,l,r) for(int i=(l);i<=(r);i++) 15 #define Clear(a,b) memset(a,b,sizeof(a)) 16 #define inout(x) printf("%d",(x)) 17 #define douin(x) scanf("%lf",&x) 18 #define strin(x) scanf("%s",(x)) 19 #define LLin(x) scanf("%lld",&x) 20 #define op operator 21 #define CSC main 22 typedef unsigned long long ULL; 23 typedef const int cint; 24 typedef long long LL; 25 using namespace std; 26 void inin(int &ret) 27 { 28 ret=0;int f=0;char ch=getchar(); 29 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=1;ch=getchar();} 30 while(ch>=‘0‘&&ch<=‘9‘)ret*=10,ret+=ch-‘0‘,ch=getchar(); 31 ret=f?-ret:ret; 32 } 33 LL l,r,a[10010],b[10010],top,n,ans; 34 bool bo[10010]; 35 LL gcd(LL a,LL b) 36 { 37 LL c; 38 while(a%b)c=a%b,a=b,b=c; 39 return b; 40 } 41 void hh(int aa,LL bb) 42 { 43 if(bb>r)return ; 44 if(aa>0)a[++top]=bb; 45 hh(aa+1,bb*10+6); 46 hh(aa+1,bb*10+8); 47 } 48 void dfs(int aa,int bb,LL cc) 49 { 50 if(aa>n) 51 { 52 if(bb&1)ans+=r/cc-l/cc; 53 else if(bb)ans-=r/cc-l/cc; 54 return; 55 } 56 dfs(aa+1,bb,cc); 57 LL temp=cc/gcd(a[aa],cc); 58 if(((long double)a[aa]*temp)<=r) 59 dfs(aa+1,bb+1,a[aa]*temp); 60 } 61 int CSC() 62 { 63 LLin(l),LLin(r); 64 hh(0,0); 65 sort(a+1,a+top+1); 66 re(i,1,top)if(!bo[i]) 67 { 68 b[++n]=a[i]; 69 re(j,i+1,top)if(!a[j]%a[i])bo[j]=1; 70 } 71 re(i,1,n)a[n-i+1]=b[i];l--; 72 dfs(1,0,1); 73 printf("%lld",ans); 74 return 0; 75 }
时间: 2024-10-12 11:09:22