Euler function -------- visible point

In the first quadrant of a Cartesian coordinate system plane, if a point (x, y) and the origin (0,0) connection is not through any other point, the point at the origin is said to be visible.
For example, the point (4,2) is not visible because it will connect through the origin point (2,1).
Part of the visible connection point to the origin as shown below:

Write a program, calculated in the case of a given integer N satisfy 0≤x, y≤N0≤x, the number of visible points (x, y) of y≤N (visible origin are not included).
Input format
The first row contains an integer C, C represents the total set of test data.
Each test per line, contains an integer N.
Output format
output test data for each line occupies.
It shall include: number of test data (starting at 1), the set of test data corresponding to the number N and the visible points.
Data between peers separated by a space.
Data range
1≤N, C≤10001≤N, C≤1000
input sample:
. 4
2
. 4
. 5
231

Output Sample:
. 1. 5 2
2 13 is. 4
. 3. 5 21 is
. 4 231 32549

Thinking: each satisfy the conditions of point x and y are relatively prime.
The number is divided into two portions in FIG, Euler function, determined to meet the conditions of point

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int primes[N], cnt;
bool st[N];
int phi[N];
void init(int n){
 phi[1] = 1;
 for (int i = 2; i <= n; i ++){
  if (!st[i]){
   primes[cnt ++] = i;
   phi[i] = i - 1;
  }
   for (int j = 0; primes[j] * i <= n; j ++){
   st[i * primes[j]] = true;
   if (i % primes[j] == 0){
    phi[i * primes[j]] = primes[j] * phi[i];
    break;
   }
   phi[i * primes[j]] = phi[i] * (primes[j] - 1);
  }
 }
}
int main(){
 init (N - 1);
 int n, m;
 cin >> m;
 for (int T = 1; T <= m; T ++){
  cin >> n;
  int res = 1;
  for (int i = 1; i <= n; i ++)   res += phi[i] * 2;
  cout << T << ' ' << n << ' ' << res << endl;
 }
 return 0;
}
Published 106 original articles · won praise 67 · views 5421

Guess you like

Origin blog.csdn.net/qq_45772483/article/details/104965770