Original question
Hang a link codeforces
The main topic: given K prime numbers, find out that only a few of the numbers in the number of combinations (can be used multiple times a number) of the first K value
Solution
Analysis:
We see that n is 16, and then if the N/2 is allowed to be over. Consider meeting in the middle
He asked us to ask for the number of K, and rightly think of the two answers.
Then we have to find out all the combinations, and then two points to judge the answer.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include < iostream> #include <queue> #include <algorithm> #define LL long Long#define re registerusing namespace std; inline int gi () {int Sum=0,f=1;char ch=getchar (); while (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' && ch<= ' 9 ') {sum= (sum<<3) + (sum<<1) +ch-' 0 '; Ch=getchar ();} return f*sum;} Inline ll GL () {ll sum=0,f=1;char Ch=getchar (); while (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' && ch<= ' 9 ') {sum= (sum<<3) + (sum<<1) +ch-' 0 '; Ch=getchar ();} return f*sum;} int n,p[20],t1,t2;ll s1[5000010],s2[5000010],k;void DFS1 (int x,ll s) {if (x>n) {S1[++t1]=s;return;} for (ll w=1;; W*=p[x]) {DFS1 (x+2,s*w); if (1e18/p[x]<w*s) break;}} void dfs2 (int x,ll s) {if (x>n) {S2[++t2]=s;return;} for (ll w=1;; W*=p[x]) {DFS2 (x+2,s*w); if (1e18/p[x]<w*s) break;}} int main () {N=gi (); for (re int i=1;i<=n;i++) P[i]=gi (); Sort (p+1,p+n+1); DFS1 (;d fs2) (2,1); Sort (s1+1,s1+t1+1); sort (s2+1,s2+t2+1); K=gi (); ll L=0,r=1e18,ans; while (L<=r) {ll mid= (l+r) >>1,tot=0; for (re int i=1,p=t2;i<=t1;i++,tot+=p) while (P && mid/s1[i]<s2[p]) p--; if (tot<k) l=mid+1; Else{ans=mid;r=mid-1;} } printf ("%lld\n", ans); return 0;}
cf912e Prime Gift (meeting in the Middle+two pointers)