http://www.spoj.com/problems/VLATTICE/
Obviously, when gcd (x, Y, z) =k,k!=1, (x, Y, z) is obscured (x/k,y/k,z/k), so this question requires the number ==1 (+{) x,y,0 (x, y) |gcd ==1 (+3{) of gcd (x, Y, z) 0,0,1 ( 0,1,0), (1,0,0)}
Now don't go to the last three points on the axis,
Set F (i) =| {(x,y,0) |gcd (x, y) ==i}|*3+| {(x, y, z) |gcd (x, Y, z) ==i}|, which is the number of greatest common divisor that are not on the axis and are not 0 coordinate values,
F (i) is the number of coordinates that are not on the axis, consisting of coordinate values divisible by I, f (i) =n/i*n/i* (n/i+3), and obviously F (i) =sigma (B|n,f[i]),
Möbius inversion, F (1) =sigma (Mul (i) *f (i))
#include <cstdio> #include <algorithm>using namespace std;const int maxn =1e6+2;bool ifprime[maxn];int mul[ Maxn];int prime[maxn];void Moblus () {ifprime[2]=true; for (int i=3;i<maxn;i+=2) ifprime[i]=true; int pnum=0; Mul[1]=1; for (int i=2;i<maxn;i++) {if (Ifprime[i]) {prime[pnum++]=i; Mul[i]=-1; } for (int j=0;j<pnum&&i*prime[j]<maxn;j++) {ifprime[i*prime[j]]=false; if (i%prime[j]==0) {mul[i*prime[j]]=0; Break } else {mul[i*prime[j]]=-mul[i]; }}}}int Main () {int T; Moblus (); scanf ("%d", &t); while (t--) {int n; scanf ("%d", &n); LonG Long ans=3; for (int i=1;i<=n;i++) {ans+= (Long Long) mul[i]* (n/i) * (n/i) * (n/i+3); } printf ("%i64d\n", ans); } return 0;}
Spoj vlattice Visible Lattice Points, inverse difficulty: 3