Poj 3090 visible lattice points Euler's Function

Source: Internet
Author: User

Link: http://poj.org/problem? Id = 3090

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, the intersection of (0, 0) and (x, y) does not pass through other points only when x and y have mutual quality. For X, when Y is equal to N, all the points that can be selected are less than or equal to N and the number of 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 <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <map>#include <cstdlib>#include <queue>#include <stack>#include <vector>#include <ctype.h>#include <algorithm>#include <string>#include <set>#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\n",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.