Bzoj 2393 Cirno's Perfect arithmetic classroom (principle of repulsion + search)

Source: Internet
Author: User
Tags gcd

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.