HDU 5212-Code

%5E2-gcd(a_i%2Ca_j)%7D&preview=true)


%E8%AE%BE%E7%BD%AE%E4%B8%80%E4%B8%AA%E4%B8%8A%E9%99%90N%3D10%5E4%7D&preview=true)
%5Csum_%7Bj%3D1%7D%5E%7BN%7Df(j)%5Ccdot%20(gcd(i%2Cj)%5E2-gcd(i%2Cj))%7D&preview=true)
%5Csum_%7Bj%3D1%7D%5E%7BN%7Df(j)%5Ccdot%20(gcd(i%2Cj)%5E2-gcd(i%2Cj))%3D%5Csum_%7BT%3D1%7D%5E%7BN%7Dg(%5Cfrac%7BN%7D%7BT%7D)%5Csum_%7Bd%7CT%7D(d%5E2-d)%5Ccdot%20%5Cmu(%5Cfrac%7BT%7D%7Bd%7D)%7D&preview=true)
%3D%5B%5Csum_%7Bi%3D1%7D%5E%7B%5Cfrac%7BN%7D%7BT%7D%7Df(i%5Ccdot%20T)%5D%5E2%7D&preview=true)
%7D&preview=true)

#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
#define sc scanf
#define itn int
#define STR clock_t startTime = clock();
#define END clock_t endTime = clock();cout << double(endTime - startTime) / CLOCKS_PER_SEC *1000<< "ms" << endl;
using namespace std;
const int N=10000+225;
const long long mod=10007;
const long long mod2=998244353;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
inline ll mul_64(ll x,ll y,ll c){return (x*y-(ll)((long double)x/c*y)*c+c)%c;}
inline ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=a*a%c)if(b&1)ans=ans*a%c;return ans;}
inline void exgcd(ll a,ll b,ll &x,ll &y){if(!b)x=1,y=0;else exgcd(b,a%b,y,x),y-=x*(a/b);}
int prime[N],tot=0,vis[N],mu[N];
ll f[N],h[N];
ll g(int n,int T){
ll ans=0;
for(int i=1;i<=n;i++){
ans+=f[i*T];
}
return ans*ans%mod;
}
int main(){
mu[1]=1;
for(int i=2;i<N;i++){
if(!vis[i])prime[++tot]=i,mu[i]=-1;
for(int j=1;j<=tot&&i*prime[j]<N;j++){
vis[i*prime[j]]=1;
if(i%prime[j]==0){
mu[i*prime[j]]=0;
break;
}else mu[i*prime[j]]=-mu[i];
}
}
for(int i=1;i<N;i++){
for(int j=i;j<N;j+=i){
h[j]+=1LL*mu[j/i]*(i*i%mod-i);
h[j]=(h[j]%mod+mod)%mod;
}
}
int n;while(cin>>n){
me(f,0);
for(int i=1,x;i<=n;i++)sc("%d",&x),f[x]++;
n=10000;
ll ans=0;
for(int i=1;i<=n;i++){
ans+=g(n/i,i)*h[i]%mod;
if(ans>=mod)ans-=ans/mod*mod;
}
printf("%lld\n",ans);
}
}