HDU 1695 GCD (rejection principle + prime factor decomposition)

Source: Internet
Author: User

HDU 1695 GCD (rejection principle + prime factor decomposition)

Preprocessing is performed first to break down the prime factor for each number.

Then, if gcd (x, y) = z, then gcd (x/z, y/z) = 1, because it is definitely not a multiple of z, therefore, if it is not a multiple of z, we can directly remove it. so we only need to divide B and d by k, and then convert it into the logarithm of the mutual quality in the two ranges. In this case, we can enumerate 1 ~ B. Then use the exclusion principle to find 1 ~ D. To avoid duplication, you only need to limit the size relationship. For details, see the code.

The Code is as follows:

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include #include 
     
      #include 
      #include 
       
        #include 
        
         using namespace std;#define LL __int64const int mod=1e9+7;const int INF=0x3f3f3f3f;LL ans;LL a, b, c, d;vector
         
          vec[110000];void dfs(LL i, int cur, int cnt, LL tmp){ tmp*=(LL)vec[i][cur]; if(cnt&1) { ans+=(LL)min(d,i)/tmp; } else { ans-=(LL)min(d,i)/tmp; } for(int j=cur+1; j
          
           1) vec[i].push_back(x); }}int main(){ int t, i, j, num=0; LL sum, k; init(); scanf("%d",&t); while(t--) { scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&k); num++; if(!k) { printf("Case %d: 0\n",num); continue ; } b/=k; d/=k; if(b
           
            

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.