题解|Visible Lattice Points
Visible Lattice Points
https://ac.nowcoder.com/acm/contest/1022/D
欧拉函数裸题。能看见就必须满足前面没有在同一斜率上的点,即,而且
,所以只需要算一半*2即可。对于每一个i,
的数的个数其实就是它的欧拉函数值..但是注意n不要算以及还有3个点最后要加就行了
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define il inline
namespace io {
#define in(a) a=read()
#define out(a) write(a)
#define outn(a) out(a),putchar('\n')
#define I_int ll
inline I_int read() {
I_int x = 0 , f = 1 ; char c = getchar() ;
while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; }
while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; }
return x * f ;
}
char F[ 200 ] ;
inline void write( I_int x ) {
if( x == 0 ) { putchar( '0' ) ; return ; }
I_int tmp = x > 0 ? x : -x ;
if( x < 0 ) putchar( '-' ) ;
int cnt = 0 ;
while( tmp > 0 ) {
F[ cnt ++ ] = tmp % 10 + '0' ;
tmp /= 10 ;
}
while( cnt > 0 ) putchar( F[ -- cnt ] ) ;
}
#undef I_int
}
using namespace io ;
using namespace std ;
#define N 1010
int p[N], cnt, n, phi[N];
int vis[N];
ll sum[N];
void calc(int n) {
phi[1] = 1;
for(int i = 2; i <= n; ++i) {
if(!vis[i]) p[++cnt] = i, phi[i] = i - 1;
for(int j = 1; j <= cnt && i * p[j] <= n; ++j) {
vis[i * p[j]] = 1;
if(i % p[j] == 0) {
phi[i * p[j]] = phi[i] * p[j];
break;
}
phi[i * p[j]] = phi[i] * (p[j] - 1);
}
}
for(int i = 2; i <= n; ++i) sum[i] = sum[i - 1] + phi[i];
}
int main() {
calc(1000);
int Cas = 0;
int T; scanf("%d", &T);
while(T--) {
scanf("%d", &n);
printf("%d %d ", ++Cas, n);
printf("%lld\n", sum[n] * 2 + 3);
}
} 