https://www.luogu.org/problemnew/show/P2158
以人所在位置为(0,0)建立坐标系,
显然除了(0,1)和(1,0)外,可以只在坐标(x,y)的gcd(x,y)==1时统计贡献。。因为如果gcd(x,y)==g而g不等于1,那么会在(x/g,y/g)处统计贡献
1要特判。。
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<vector> 5 using namespace std; 6 #define fi first 7 #define se second 8 #define mp make_pair 9 #define pb push_back 10 typedef long long ll; 11 typedef unsigned long long ull; 12 typedef pair<int,int> pii; 13 #define N 100100 14 ll prime[N+100],len,mu[N+100]; 15 bool nprime[N+100]; 16 ll n,ans; 17 ll F(ll x) {return (n/x)*(n/x);} 18 int main() 19 { 20 ll i,j; 21 mu[1]=1; 22 for(i=2;i<=N;i++) 23 { 24 if(!nprime[i]) prime[++len]=i,mu[i]=-1; 25 for(j=1;j<=len&&i*prime[j]<=N;j++) 26 { 27 nprime[i*prime[j]]=1; 28 if(i%prime[j]==0) {mu[i*prime[j]]=0;break;} 29 else mu[i*prime[j]]=-mu[i]; 30 } 31 } 32 scanf("%lld",&n); 33 if(n==1) {puts("0");return 0;} 34 n--; 35 for(i=1;i<=n;i++) ans+=mu[i]*F(i); 36 printf("%lld",ans+2); 37 return 0; 38 }
https://www.luogu.org/problemnew/show/P1447
一样的。。。
答案就是$sum_{i=1}^nsum_{j=1}^m{(2*gcd(i,j)-1)}$
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<vector> 5 using namespace std; 6 #define fi first 7 #define se second 8 #define mp make_pair 9 #define pb push_back 10 typedef long long ll; 11 typedef unsigned long long ull; 12 typedef pair<int,int> pii; 13 #define N 100000 14 ll prime[N+100],len,mu[N+100]; 15 bool nprime[N+100]; 16 ll n,m,ans,a2; 17 ll F(ll x) {return (m/x)*(n/x);} 18 int main() 19 { 20 ll i,j,k; 21 mu[1]=1; 22 for(i=2;i<=N;i++) 23 { 24 if(!nprime[i]) prime[++len]=i,mu[i]=-1; 25 for(j=1;j<=len&&i*prime[j]<=N;j++) 26 { 27 nprime[i*prime[j]]=1; 28 if(i%prime[j]==0) {mu[i*prime[j]]=0;break;} 29 else mu[i*prime[j]]=-mu[i]; 30 } 31 } 32 scanf("%lld%lld",&n,&m); 33 if(n>m) swap(n,m); 34 for(k=1;k<=m;k++) 35 { 36 a2=0; 37 for(i=1;i<=m/k;i++) 38 a2+=mu[i]*F(i*k); 39 ans+=a2*k; 40 } 41 printf("%lld",ans*2-n*m); 42 return 0; 43 }
http://210.33.19.103/contest/776/problem/2
完全不会。。