AcWing 201. 可见的点
原题链接
简单
作者:
66brother
,
2021-07-21 14:42:04
,
所有人可见
,
阅读 314
- 先从结论说起,首先一条线的斜率 (y - 0) / (x - 0) = y / x,同样斜率的线只会有一个点,其它的点都会被这个点给挡住
- 这个点的y 和 x 肯定是互质的 gcd(x, y) = 1
- 欧拉函数搞一搞,有3个特殊点,其他都 res + E[2 : N] * 2
Java 代码
// Don't place your source in a package
import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;
// Please name your class Main
public class Main {
static FastScanner fs=new FastScanner();
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreElements())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int Int() {
return Integer.parseInt(next());
}
long Long() {
return Long.parseLong(next());
}
String Str(){
return next();
}
}
public static void main (String[] args) throws java.lang.Exception {
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
//reading /writing file
//Scanner sc=new Scanner(new File("input.txt"));
//PrintWriter pr=new PrintWriter("output.txt");
int T=Int();
for(int t=0;t<T;t++){
int n=Int();
Solution sol=new Solution(out);
sol.solution(n,t);
}
out.close();
}
public static int[] Arr(int n){
int A[]=new int[n];
for(int i=0;i<n;i++)A[i]=Int();
return A;
}
public static int Int(){
return fs.Int();
}
public static long Long(){
return fs.Long();
}
public static String Str(){
return fs.Str();
}
}
class Solution {
PrintWriter out;
int INF = Integer.MAX_VALUE;
int MOD = 1000000009;
int mod = MOD;
public Solution(PrintWriter out) {
this.out = out;
}
public void solution(int N,int t) {
int res=3;
int E[]=euler(N+10);
for(int i=2;i<=N;i++)res+=(E[i]*2);
out.println((t+1)+" "+N+" "+res);
}
public int[] euler(int n) {
int E[]=new int[n+1];
E[1]=1;
for(int i=2;i<E.length;i++)
E[i]=i;
for(int i=2;i<E.length;i++){
if(E[i]==i)
{
for(int j=i;j<E.length;j+=i){
E[j]=E[j]/i*(i-1);
}
}
}
return E;
}
}