POJ 3090 Visible Lattice Points Euler's Function

Source: Internet
Author: User

POJ 3090 Visible Lattice Points Euler's Function

 

In the coordinate system, select a point from the point 0 ≤ x, y ≤ N in the x and y ≤ N, and these points do not pass through other points.

Idea: Obviously, only when x and y are in mutual quality will the intersection of (0, 0) and (x, y) not pass through other points. For x, when y is equal to N, you can select a number of points less than or equal to N that are in mutual quality with N. A total of Euler (N) points are not overlapped. So we can obtain the recursive formula aa [I] = aa [I] + 2 * Euler (N ).
Code:

 

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include
     #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include #include 
           
            #include 
            
             #define PI acos(-1.0)#define maxn 10005#define INF 0x7fffffff#define eps 1e-8typedef long long LL;typedef unsigned long long ULL;using namespace std;int aa[1005];int Euler(int tot){ int num=tot; for(int i=2; i<=tot; i++) { if(tot%i==0) num=num/i*(i-1); while(tot%i==0) tot/=i; } return num;}void init(){ aa[0]=0; aa[1]=3; for(int i=2; i<=1000; i++) aa[i]=aa[i-1]+Euler(i)*2;}int main(){ int T; scanf(%d,&T); init(); for(int ii=1; ii<=T; ii++) { int tot; scanf(%d,&tot); printf(%d %d %d,ii,tot,aa[tot]); } 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.