BZOJ 2393 Cirno's perfect principle of classroom rejection + DFS
Warning all questions on the Internet are incorrect. Before reading this question, Please eliminate all the comments on the common online questions written before this question.
The data range of this question is 10 ^ 9, but 10 ^ 10 can be the same without any impact.
First, we can pre-process 1 ~ Within r, all the shards consisting of 2 and 9 are easy to find up to 1022
However, some of the values are multiples. For example, if a is a multiple of B, if a number is a multiple of a, it must be a multiple of B. We only need to calculate B. a. pruning is supported here.
The number of all workers that are not multiples of another number should have a maximum of 466 evaluate the number of multiples of these numbers in the interval.
Total number = the number of multiples of a single number-the number of two public multiples + the number of three public multiples ......
For example, to enumerate the public multiples of a certain number of n, perform lcm on the number of n, and then use r/lcm as 1 ~ The number of public multiples of the n numbers in r is
But the 2 ^ 466 enumeration is obviously not possible. We found that most of the 466 numbers are relatively large. Just select a few and do the LCM to blow up r.
Therefore, we chose to search for the complexity of 2 ^ 466, but we can pruning it. When the current LCM is greater than r, after pruning, it will not be much more than 1 s.
[Brainless time, not pleasing to the eye]
What does Nima write on the TM online !!! The TM says there are only 30 screens !! You don't want to see if the screen is a prime number !!! If there are only 30 tables, why don't you create them ???
Do you know how many people your ** questions have misled !! Even when a is dividing B, no one knows who is the multiple of who is to guide others ?!! Write [if (! A [j] % a [I])] Hasn't I ever written a number theory ???
Really ...... I saw this question when I used to refresh the principle. I read the question. It's just a long time since I got a cloud card.
Even if the problem is completely beyond the limit, it is really enough to write code.
#include
#include
#include
#include#define MAX 1000000000llusing namespace std;long long l,r,ans,a[1050],b[1050];bool v[1050];void DFS1(long long x){if(x>r) return;a[++a[0]]=x;DFS1(x*10+2);DFS1(x*10+9);}void DFS2(int pos=1,int flag=-1,long long now=1){if(!b[pos]){if(now^1)ans+=(r/now-(l-1)/now)*flag;return ;}DFS2(pos+1,flag,now);long long temp=now*b[pos]/__gcd(now,b[pos]);if(temp>r) return ;DFS2(pos+1,-flag,temp);}int main(){int i,j,cnt=0;cin>>l>>r;DFS1(2);DFS1(9);sort(a+1,a+a[0]+1);for(i=1;a[i];i++)for(j=i+1;a[j];j++)if(a[j]%a[i]==0)v[j]=1;for(i=1;a[i];i++)if(!v[i])b[++b[0]]=a[i];DFS2();cout<