10.06 tolerance Practice T3 simple tolerance + go to re-search

Source: Internet
Author: User
Tags gcd

Description~cirno found a Baka number, this number ~ only 2 and ⑨ two kinds of numbers ~ ~
Now Cirno want to know ~ an interval ~ ~ How many numbers can be divisible by Baka number ~
But Cirno is so talented that the goblins don't bother to count.
You can only rely on the smart you. Input line integer L R (1 < L < R < 10^10) output a positive integer representing the answer to the sample INPUT1 100Sample Output58 The lucky number of the previous scoi is actually a good thing, that is, preprocessing Out all the 2,9-related numbers, and then the numbers go back in and run (if it's pretty scary, 18000+ 446) Search Search is very common, pay attention to the next shift is LCM, others see lucky Number (once on the very rare) code:
1#include <iostream>2#include <cstdio>3#include <algorithm>4 #defineN 1000055 using namespacestd;6 Long LongAns,a[n],l,r,tot,check[n];7 voidPreLong LongDepLong Longval) {8 //cout<<val<<endl;9 //System ("pause");Ten     if(dep==9){ One         if(!val)return; Aa[++tot]=Val; -         return; -     } thePre (dep+1, val*Ten+2); -Pre (dep+1, val*Ten+9); -Pre (dep+1, Val); - } + voidUni () { -Sort (A +1, a+tot+1); +Tot=unique (A +1, a+tot+1)-a-1; A     Long Longtemp=0; at     Long Longb[20000]; -      for(Long LongI=1; i<=tot;i++) b[i]=A[i]; -      for(Long LongI=1; i<=tot;i++){ -         if(Check[i])Continue; -a[++temp]=B[i]; -          for(Long Longj=i+1; j<=tot;j++){ in             if(B[j]%b[i])Continue; -check[j]=1; to         }     +     } -tot=temp; the     return; * } $ Long LonggcdLong LongALong Longb) {Panax Notoginseng     if(a<b) Swap ( A, a); -      while(a=a%b) Swap ( A, a); the     returnb; + } A Long LongLcmLong LongALong Longb) { the     returnA/GCD (A, b) *b; + } - voidDfsLong LongDepLong LongValintNow ) { $     if(Val>r)return; $     if(dep==tot) { -         if(val==1)return; -     //cout<<val<<endl; the         if(now%2==1) -ans+=r/val-(l1)/Val; Wuyi         Else theans-=r/val-(l1)/Val; -         return ; Wu     } -DFS (dep+1, LCM (val,a[dep+1]), now+1); AboutDFS (dep+1, Val,now); $ } - intMain () { -Pre0,0); - Uni (); A //for (int i=1;i<=tot;i++) { + //cout<<a[i]<<endl; the //if (i%100==0) - //System ("pause"); $ //    } theCin>>l>>R; theDfs0,1,0); thecout<<ans; the     return 0; -}

Over

10.06 tolerance Practice T3 simple tolerance + go to re-search

Related Article

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.