Given n positive integers a1,a2,... ,an, beg
Value (answer modulo 10^9+7).
Input
The first line is a positive integer n. Next n rows, one positive integer per line, A1,a2,..., an.
Output
Only one line of answers.
Sample Input
361015
Sample Output
1595
Hint
1<=n<=10^5,1<=ai<=10^7. A total of 3 sets of data.
Main Topic (The topic is too concise to be careless at all)
Although the topic is very concise, but everywhere digging a hole waiting for you to jump.
The original plan was two hours to finish today's example a, actually two hours have been the problem of the hole (lazy to re-push the formula ... )
Suppose the reader knows what the integrable function is and the product of the Euler function
The product of Euler's function can be expressed in this form (the P + subscript in it represents a different prime number):
So, we can separate each of the prime numbers to contribute to the calculation, and then the product (because we have each like the above form split to find Phi value, so is the product).
So we succeeded in getting a longer formula: (where B (P) I represents the exponent of the AI's mass factor p)
Since the Euler function is not good at using some routines to quickly find the result, consider using the magical nature of the Eulerian function to disassemble it. We know about the Euler function (again, p is prime)
Although it is a special case when the index is 0, it is not so special to add black technology:
is a drop, add a 1/p to solve the problem. Now continue to simplify:
The time complexity of the calculation can be accepted at this point. However, due to the modulo meaning to do division need to multiply the inverse, because p is less than 1e7 prime number, so must and 1E9 + 7 coprime, so the inverse must exist.
There is something magical about this problem, what are the different primes with STL (standard Templates Library sometimes/ Standard Tle/mle Library), however MLE ... Ask for explanation ... It's not quite the same as the theory.
So just use a black tech. The first position of the pair is what prime number is, and the second is the index. Then sort it out and you can get AC.
Code
1 /**2 * Bzoj3 * problem#35604 * Accepted5 * Time:1276ms6 * memory:7940k7 */8#include <bits/stdc++.h>9 #ifndef WIN32Ten #defineAuto "%lld" One #else A #defineAuto "%i64d" - #endif - using namespacestd; thetypedefBOOLBoolean; - #defineSmax (A, b) a = Max (A, B) - #defineLL Long Long - + Const intModer = 1e9 +7; - ll Mpow (ll A, ll pos) { + if(pos = =0)return 1; A if(pos = =1)returnA; atLL temp = Mpow (A, POS >>1); -TEMP = (temp * temp)%Moder; - if(POS &1) TEMP = (temp * a)%Moder; - returntemp; - } - in voidEXGCD (ll A, ll B, ll& D, ll& x, ll&y) { - if(!b) { toD =A; +x =1, y =0; -}Else { theEXGCD (b, a%B, D, y, x); *Y-= (A/b) *x; $ }Panax Notoginseng } - the intInvintAintModer) { + LL D, x, y; A EXGCD (A, moder, D, X, y); the return(X <0) ? (x +moder): (x); + } - $ Const intLimit =3500; $ intnum =0; - intprime[ +]; -Boolean Vis[limit +1]; theInlinevoidEuler () { - for(inti =2; I <= limit; i++) {Wuyi if(!vis[i]) prime[num++] =i; the for(intj =0; J < num && i * prime[j] <= limit; J + +) { -Vis[i * Prime[j]] =true; Wu if((i% prime[j] = =0)) - Break; About } $ } - } - - intN; A int*arr; + intCNT =0; thepair<int,int> ds[800005]; -Inlinevoidinit () { $scanf"%d", &n); thearr =New int[(n +1)]; the for(inti =1; I <= N; i++) { thescanf"%d", arr +i); the } - } in theLL Getsum (intPintc) { theLL a = (Mpow (p, C +1) -1); AboutLL b = INV (P-1, moder); the return(A * b)%Moder; the } the +LL res =1; -Inlinevoidsolve () { the for(inti =1, X; I <= N; i++) {Bayix =Arr[i]; the for(intj =0; PRIME[J] * Prime[j] <= x && arr[i] >1; J + +) { the if((Arr[i]% prime[j]) = =0) { -Ds[cnt].first = Prime[j], Ds[cnt].second =0; - while((Arr[i]% prime[j]) = =0) theArr[i]/= Prime[j], ds[cnt].second++; thecnt++; the } the } - if(Arr[i] >1) theDs[cnt].first = Arr[i], Ds[cnt++].second =1; the } theSort (ds, DS +CNT);94 the intp, C; the for(intID =0; ID <CNT;) { thep =Ds[id].first;98LL P =1; About for(inti = ID; (ID < cnt && ds[i].first = = Ds[id].first)? (true): (id = i,false); i++) { -c =Ds[i].second;101p = (p * getsum (P, c))%Moder;102 }103p = ((p * (P-1) +1)% moder) * INV (P, moder)%Moder;104res = (res * P)%Moder; the }106 printf (Auto, res);107 }108 109 intMain () { the Euler ();111 init (); the solve ();113 return 0; the}
Bzoj 3560 Dzy Loves Math V-Linear sieve-Number theory-extended Euclidean algorithm