Test instructions
Defines the number of C numbers that contain only numbers 2 and 9, and the number of [l,r] that are divisible by C numbers.
Ideas
DFS preprocessed a number of C and removed multiple cases.
DFS search occurrences, odd plus, even minus, when the value is greater than R pruning.
Code
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6typedefLong Longll;7 Const intN = 2e3+Ten;8 9 ll A[n],b[n],vis[n],ans,tot,n,l,r;Ten One voidGet_pre (intnum) A { - if(Num>r)return ; - if(num) a[++tot]=num; theGet_pre (num*Ten+2); -Get_pre (num*Ten+9); - } - ll gcd (ll A,ll b) + { - returnb==0? A:GCD (b,a%b); + } A voidDfsintCurintcnt,ll LCM) at { - if(cur==n+1) { - if(cnt&1) ans+=r/lcm-(l1)/LCM; - Else if(CNT) ans-=r/lcm-(L-1)/LCM; - return ; - } inDFS (cur+1, CNT,LCM); -ll val=lcm*a[cur]/(GCD (Lcm,a[cur])); to if(val<=r) DFS (cur+1, cnt+1, Val); + } - the intMain () * { $scanf"%lld%lld",&l,&R);Panax NotoginsengGet_pre (0); -Sort (A +1, a+tot+1); the for(intI=1; i<=tot;i++) + if(!Vis[i]) { Ab[++n]=A[i]; the for(intj=i+1; j<=tot;j++) + if(a[j]%a[i]==0) vis[j]=1; - } $ for(intI=1; i<=n;i++) $a[i]=b[n-i+1]; -Dfs1,0,1); -printf"%lld\n", ans); the return 0; -}
Bzoj 2393 Cirno's Perfect arithmetic classroom (principle of repulsion + search)