CodeTime
limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): Accepted submission (s): 27
Problem Descriptionwld likes playing with codes. One day and 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;
}
Inputthere is multiple Cases. (At most ten )
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) .
Outputfor each case:
Print an integer,denoting what the function returns.
Sample Input
51 3 4) 2 4
Sample Output
Hintgcd (x, y) means the greatest common divisor of x and Y.
Sourcebestcoder Round #39 ($)
Recommendhujie | We have carefully selected several similar problems for you:5213 5209 5208 5205 5204
Give you an an an array, let you calculate the result of that code, with the principle of tolerance to the OK, MO, the inverse of the black, but no mo than the Orz (also the principle of repulsion) ... Learn it another day.
The code is as follows:
#include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include < Cstring> #include <map>using namespace std;typedef long long ll;const int MAXN = 1e4 + 10;const ll mod = 10007; #def Ine Rep (i,a,b) for (int i= (a);i< (b); i++) #define PB Push_backint cnt[maxn],a[maxn];ll d[maxn];int main () {int n; while (~SCANF ("%d", &n)) {int mgcd = 1; for (int i = 0; i < n; i++) {int x; scanf ("%d", &x); MGCD = max (mgcd,x); A[i] = x; } memset (Cnt,0,sizeof (cnt[0]) *mgcd+20); for (int i = 0; i < n; i++) cnt[a[i]]++; ll ans = 0,res = 0; /*d[i] represents the number of scenarios for which the number of GCD for i is two */for (ll i = MGCD; i > 0; i--) {ll tot = 0; for (ll j = i; j <= mgcd; j+= i) {tot + = Cnt[j]; D[i] = (D[i]-d[j])%mod;/* the number of schemes minus the multiples of the gcd (the principle of repulsion) */ The number of methods for I is equal to the two number of options (/*GCD) is the scheme of multiples of I to remove GCD as a multiple of I (the front has been lost) */d[i] = (D[i] + Tot*tot)%mod; Ans = (d[i]*i*i)%mod; res = (Res+i*d[i])%mod; } cout<< ((ans-res)%mod+mod)%mod<<endl; } return 0;}
Hdu 5212 (Tolerant principle)