Hdu2588 GCD (Euler's function)

Source: Internet
Author: User

Hdu2588 GCD (Euler's function)

Solve the number of I with less than n and with gcd (I, n) greater than m

Analysis:

For all the largest convention values less than n, it must be a factor of n. Therefore, start from this aspect and find the factor I is n. When I> m, solve the prime number multiple of car I and accumulate the number less than n. We thought that the maximum value of this number is n/I, so we can accumulate the Euler's function value of n/I.

The Code is as follows:

# Include
 
  
# Include
  # Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include
          
            # Include
           
             # Include
            
              # Include
             
               Using namespace std; long euler (long n) {// returns euler (n) long res = n, a = n; for (long I = 2; I * I <= a; I ++) {if (a % I = 0) {res = res/I * (I-1 ); // division is performed first to prevent intermediate data overflow while (a % I = 0) a/= I ;}} if (a> 1) res = res/a * (A-1); return res;} // Euler's function value long a [1000010]; int main () {long n, m; int t; cin> t; while (t --) {long ans = 0; scanf ("% I64d % I64d", & n, & m); for (int I = 1; I * I <= n; I ++) {// determine sqrt (n). if (n % I! = 0) continue; if (I> = m & I * I! = N) {ans + = euler (n/I);} if (n/I> = m) {ans + = euler (I); // one is I, one is n/I
             
            
           
          
         
        
       
      
     
    
   
 
            }        }        printf("%I64d\n",ans);    }    return 0;}

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.