Code
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 587 Accepted Submission(s): 227
Problem Description
WLD likes playing with codes.One day he is writing a function.Howerver,his computer breaks down because the function is too powerful.He is very sad.Can you help him?
The function:
int calc
{
int res=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
res+=gcd(a[i],a[j])*(gcd(a[i],a[j])-1);
res%=10007;
}
return res;
}
The function:
int calc
{
int res=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
res+=gcd(a[i],a[j])*(gcd(a[i],a[j])-1);
res%=10007;
}
return res;
}
Input
There are Multiple Cases.(At MOST
10
)
For each case:
The first line contains an integer N(1≤N≤10000) .
The next line contains N integers a1,a2,...,aN(1≤ai≤10000) .
For each case:
The first line contains an integer N(1≤N≤10000) .
The next line contains N integers a1,a2,...,aN(1≤ai≤10000) .
Output
For each case:
Print an integer,denoting what the function returns.
Print an integer,denoting what the function returns.
Sample Input
5 1 3 4 2 4
Sample Output
64Hintgcd(x,y) means the greatest common divisor of x and y.#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #define ll long long #define mod 10007 using namespace std; int cnt[10010]; int a[10010]; int main() { int n,m; ll i,j; int x,tmp,ans; while(scanf("%d",&n)!=EOF) { memset(cnt,0,sizeof(cnt)); for(i=1;i<=n;i++) { scanf("%d",&m); x=(int)sqrt(m); for(j=1;j<=x;j++) { if(m%j!=0) continue; cnt[j]++; if(m/j!=j) cnt[m/j]++; } } ans=0; for(i=10000;i>=1;i--) { a[i]=cnt[i]*cnt[i]%mod; for(j=i*2;j<=10000;j+=i) a[i]=(a[i]-a[j]+mod)%mod; tmp=i*(i-1)%mod; ans=(ans+a[i]*tmp%mod)%mod; } printf("%d\n",ans); } return 0; }