Test instructions: Two numbers A and b are found in a sequence, which causes the a*b to have the most number of factors and the maximum number of outputs.
Ideas: More data, processing will be very slow. The number of prime factorization for each number in the sequence, and then the number of factors in descending order, the number of the first 50 factors to violence 22 of the product of the number of factors on the line. The result will be around 1s. Less than 50 will be WA.
1#include <bits/stdc++.h>2 using namespacestd;3 inta[100005];4pair<int,int> pa[100005];5 intGetallfactors (intX, vector<int> &vect)//Help! 6 {7 for(intj =2; J * J <= X; ++j)8 {9 while(x% J = =0)TenVect.push_back (j), X/=J; One } A if(x>1) - vect.push_back (x); - returnvect.size (); the } - - intGetfactors (vector<int> &num) - { +vector< vector<int> >All ; - all.resize (Num.size ()); + for(intI=0; I<num.size (); i++) A getallfactors (Num[i], all[i]); at -vector<int>tmp; - for(intI=0; I<all.size (); i++) - Tmp.insert (Tmp.end (), All[i].begin (), All[i].end ()); - sort (Tmp.begin (), Tmp.end ()); - in intz=1; - for(inti =0; I < tmp.size (); i++) to { + intL =i; - while(L < Tmp.size () && tmp[l] = =Tmp[i]) the++l; *Z *= l-i +1; $i = L-1;Panax Notoginseng } - returnZ; the } + A intFactors (intN) the { + if(1= = N)return 1; - intCNT =2; $ for(intj =2; J * J <= N; J + +) $ { - if(N% J = =0) - { thecnt++; - if(J * J! =N)Wuyicnt++; the } - } Wu returnCNT; - } About $ intMain () { - //freopen ("Input.txt", "R", stdin); - intT; - while(cin>>t) A { + for(intI=0; i<t; i++) the { -scanf"%d",&a[i]); $pa[i]=Make_pair (factors (a[i]), a[i]); the } the theSort (pa,pa+t); theReverse (pa,pa+t); -vector<int>tmp; in intn = t> -? -: t; the intans=0; the for(intI=0; i<n; i++) About { the for(intJ=i; j<n; J + +) the { the tmp.clear (); + Tmp.push_back (pa[i].second); - Tmp.push_back (pa[j].second); thecn1=Max (Getfactors (TMP), ans);Bayi } the } thecout<<ans<<Endl; - } - return 0; the}
AC Code
Hihocoder #1165: Puzzle game (Challenge B)