Visible Lattice Points POJ - 3090 (Farley sequence Euler function)

Visible Lattice Points POJ - 3090

Topic links: https://vjudge.net/problem/POJ-3090#author=lanti

topic:

 

 


Input n, Q coordinates from (0,0) to see how many points, the coordinate point is the range 0 <= (x, y) <= n
only one point to another point is not blocked to see.
FIG above, n = 5, when 21 points to see

The first input line t, represents the number of samples. 1 <= t <= 1000 Next t rows, each row enter a positive integer n. 1 <= n <= 1000Output output n rows and three columns. The first column represents an i-th sample, the output of the second column n, the output point of the third column can be seen from the number 1 to n Sample Input
4
2
4
5
231
Sample Output
. 1. 5 2 
2 13 is. 4 
. 3. 5 21 is 
. 4 231 32549 

ideas: This question actually occur slope very easy to handle, such as coordinates (1,2), (2,4), (3,6) in the same line on, so seen as a point,
as long as the rear coordinates y / x may again about time-sharing, i.e., gcd (x, y)! = 1, then the slope of this fact, already before the point
is no longer considered, when the slope is 1,0, respectively, and only in the absence of a point, it is beginning to be 3, then the triangle half seek points,
3 + 2 * is the point of the answer, the point region is 1 ~ n and n prime number, i.e. the value of the Euler, play table after obtaining the initial value of the value of the Euler 3.
After the previous value plus the current value of the Euler * 2 can be.
For example, when n = 4, the inner half of the triangle does not include a triangular border, 3 / 4,2 / 4,1 / 4, 4 seeking molecule slope coprime to the number (i.e. the value of the Euler), and finally is multiplied by
2, plus three points to three at the boundary line.
Farley sequence with a sequence consisting of all similar slope,
Farley sequence: for any given one of the natural number n, the denominator arranged in ascending order irreducible proper fraction less than n, and before the first score by the number of 0/1, while in the last fraction after adding 1/1, this sequence is referred to as n-level mine sequence method

//
// Created by hanyu on 2019/8/9.
//
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include<math.h>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=3e6+7;
#define MAX 0x3f3f3f3f
int euler[maxn];
void value()
{
    memset(euler,0,sizeof(euler));
    euler[1]=1;
    for(int i=2;i<=maxn;i++)
    {
        if(!euler[i])
        {
            for(int j=i;j<=maxn;j+=i)
            {
                if(!euler[j])
                    euler[j]=j;
                euler[j]=euler[j]/i*(i-1);
            }
        }
    }
    euler[1]=3;
    for(int i=2;i<=maxn;i++)
        euler[i]=euler[i-1]+euler[i]*2;
}
int main()
{
    int T,casee=0;
    value();
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        printf("%d %d %d\n",++casee,n,euler[n]);
    }
    return 0;
}

 

 

 

Guess you like

Origin www.cnblogs.com/Vampire6/p/11330176.html