Topic 4: Money is a wayward time limit:10000msSingle Point time limit:1000msMemory Limit:256MB
Describe
As the saying goes, money is willful. We are going to see a movie for our high-enriched fish ball. After the fish ball arrived at the cinema, it was found that the number of seats was exactly 1 to 200.
But there are some seat numbers corresponding to the seat broken, unable to sit, may as well assume that there are still n seats to sit. The owner of the movie tells the fish pill that if you want to pack all the chairs in a set of S, you'll have to pay the number of these chairs for the least common multiple money. The fish pill was very willful.
After coming here for a lot of days, the fish pill found itself exactly 2n-1 days, and because he was very headstrong, he wrapped his eyes down to the movies for every possible non-empty set of the n chairs. Fish pill Gentleman Although it does not care how much money spent, but you are his assistant after all, so you want to know how much the fish pill cost. Since the amount of money is too large, please output the answer mod9+7.
Input
The first line enters a number n (1 <= n <= 200), indicating the number of chairs that can be made.
The next line is n an integer between 1 and 200, separated by a space.
Output
One line to output the answer.
-
-
Sample input
-
-
22 4
-
-
Sample output
-
-
10
The subject is DP, but the map does not save that large number (LCM,..., 200), so consider compressing
easy to think of ≤n number P >sqrt (n) appears only once,
So they can be compressed a1*a2*...*a[m-1]*p=n compressed to A1*a2*...*a[m-1]
F (i) indicates the number of lcm=i
Because let F (A1*a2*...*a[m-1]) +=p*f (a1*a2*...*a[m-1]*p) does not affect the result, it is possible,
It is important to note that the number in F () may be more than F, the first to take the mold to prevent overflow
#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include < functional> #include <iostream> #include <cmath> #include <cctype> #include <ctime> #include <map>using namespace std; #define for (I,n) for (int. i=1;i<=n;i++) #define FORK (i,k,n) for (int i=k;i<=n;i++) # Define REP (I,n) for (int. i=0;i<n;i++) #define ForD (I,n) for (int. i=n;i;i--) #define REPD (i,n) for (int i=n;i>=0;i--) # Define Forp (x) for (int p=pre[x];p, p=next[p]) #define FORPITER (x) for (int &p=iter[x];p; p=next[p]) #define Lson (x< <1) #define Rson ((x<<1) +1) #define MEM (a) memset (A,0,sizeof (a)), #define MEMI (a) memset (A,127,sizeof (a)); Define Memi (a) memset (A,128,sizeof (a)), #define INF (2139062143) #define F (1000000007) #define MAXN (2000+10) #define N ( A long long mul (long long A,long long B) {return (a*b)%F;} Long Long (long A,long long B) {return (a+b)%F;} Long Long sub (long A,long long B) {return (a-b+ (a)/f*f+f)%F;} typedef long LONGLl;void upd (ll &a,ll b) {a= (a+b)%F;} int N,a[maxn],p[maxn],tot=0;bool b[maxn]={0};map<ll,ll> f[2];ll gcd (ll a,ll b) {if (b==0) return A;return gcd (b,a%b );} ll LCM (ll A,ll b) {return a/gcd (b) *b;} void Make_prime (int n) {Fork (i,2,n) {if (!b[i]) p[++tot]=i; for (J,tot) {if (i*p[j]>n) break;b[i*p[j]]=1;if (i%p[j]==0) break; }}}int Cnt[maxn]={0};ll pw2[maxn]={ 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,1 6777216,33554432,67108864,134217728,268435456,536870912,73741817,147483634,294967268,589934536,179869065,359738130,719476 260,438952513,877905026,755810045,511620083,23240159,46480318,92960636,185921272,371842544,743685088,487370169,974740338 , 949480669,898961331,797922655,595845303,191690599,383381198,766762396,533524785,67049563,134099126,268198252,536396504,7 2793001,145586002,291172004,582344008,164688009,329376018,658752036,317504065,635008130,270016253,540032506,80065005,1601 30010,320260020,640520040,281040073,562080146,124160285,248320570,496641140,993282280,986564553,973129099,946258191,892516375,785032743,570065479,140130951 , 280261902,560523804,121047601,242095202,484190404,968380808,936761609,873523211,747046415,494092823,988185646,976371285 , 952742563,905485119,810970231,621940455,243880903,487761806,975523612,951047217,902094427,804188847,608377687,216755367 , 433510734,867021468,734042929,468085851,936171702,872343397,744686787,489373567,978747134,957494261,914988515,829977023 , 659954039,319908071,639816142,279632277,559264554,118529101,237058202,474116404,948232808,896465609,792931211,585862415 , 171724823,343449646,686899292,373798577,747597154,495194301,990388602,980777197,961554387,923108767,846217527,692435047 , 384870087,769740174,539480341,78960675,157921350,315842700,631685400,263370793,526741586,53483165,106966330,213932660,42 7865320,855730640,711461273,422922539,845845078,691690149,383380291,766760582,533521157,67042307,134084614,268169228,5363 38456,72676905,145353810,290707620,581415240,162830473,325660946,651321892,302643777,605287554,210575101,421150202,842300404,684600801,369201595,738403190,476 806373,953612746,907225485,814450963,628901919,257803831,515607662,31215317,62430634,124861268,249722536,499445072 };bool Use[maxn]={0};int Main () {//freopen ("hiho1113.in", "R", stdin);//freopen ("Hiho1113.out", "w", stdout); Make_ Prime (;cin>>n;) for (i,n) Cin>>a[i],cnt[a[i]]++;bool ct=0;f[0][1]=1; Suppose at first there is an empty set LCM (φ) =1, obviously LCM (φ,a,b,c.). =LCM (a,b,c.)//followed by {solution set}+ element i ForD (j,tot) if (p[j]*p[j]>n)//If p[j]*k=n=200 k<sqrt (N) <p[j] {for (int k=1;k<= n/p[j];k++) {int i=k*p[j];use[i]=1;if (!cnt[i]) continue;for (Map<ll,ll>::iterator it=f[ct].begin (); IT!=F[CT]. End (); it++) {ll c=it->first,v=it->second;upd (f[ct^1][c],f[ct][c]);//It is possible to have the upd changed before the LCM (F[CT^1][LCM (c,i)],mul ( F[ct][c],sub (pw2[cnt[i]],1)));} F[ct].clear (); ct^=1;} Obviously P[j] appears up to 1 times, and then does not appear, so the p[j] "delete" to not answer the effect f (i) means LCM (..) Number of =i//eg cost=2*f (2) +2*56*f (2*56) = 2*f (2) f (2) = (f (2) +56*f (2*56))//Add 17-> F (2*17) =f (2*17) +56*f (2*17*56) for (Map<ll,ll>::iterator It=f[ct].begin (); It!=f[ct].end (); it++) {ll c=it- >first,v=it->second;if (c%p[j]==0) upd (F[ct^1][c/p[j]],mul (v,p[j)), Else upd (f[ct^1][c],v);} F[ct].clear (); ct^=1;} for (I,n) {if (Use[i]) continue;if (!cnt[i]) continue;for (Map<ll,ll>::iterator it=f[ct].begin (); It!=f[ct].end () ; it++) {ll c=it->first,v=it->second;upd (f[ct^1][c],f[ct][c]);//may have changed the upd before the LCM (F[CT^1][LCM (c,i)],mul (F[CT] [C],sub (pw2[cnt[i]],1)));} F[ct].clear (); ct^=1;} ll Ans=0;for (Map<ll,ll>::iterator it=f[ct].begin (); It!=f[ct].end (); it++) upd (Ans,mul ((It->first)%F, (it- >second) (%F)); Cout<<sub (ans,1) <<endl;return 0;}
Hiho Challenge 7 (money is a factor of willful-DP and prime numbers)