https://www.zybuluo.com/ysner/note/1300802 Problem surface
Given a positive integer \ (n\) and \ (k\), ask whether \ (n\) can be decomposed into the product of \ (k\) different positive integers.
\ (n\leq10^9,k\leq20,t\leq4000\)
AnalyticalThis problem Kathang, delete a bunch of define fast one times
You can find \ (12!=479001600>10^9\).
So \ (n\) is broken down into \ (11\) a different positive integer at most.
General operation: Find out all approximate and then \ (O (2^{11}) \) enumeration plus pruning.
However I will not search Ah,\ (tle\) for one hours.
To add these pruning.
- Multiply the smallest ( t\)(the number of not selected) is greater than \ (n\), then \ (return\)
- The search process is not an enumeration of the number of choices, but rather an enumeration of the next hop to which number
The only consequence of this pruning is to get rid of \ (define\) and unnecessary libraries in the program (I also went to read optimization).
Then \ (bzoj\) from \ (tle\) into the time limit of half ... Spicy Chicken Card Common problem ...
And then I wrote a summary and thought of a
- If \ (k!>n\), then \ (continue\)
#include <iostream> #include <cstdio> #include <algorithm>using namespace Std;const int N=2000;int n,k , Sta[n],top,las,f[n][22];long long jc[22];int dfs (int x,int t,int s) {if (!t) return s==n; for (--t;x+t<=top;++x) {if (f[x][t]<0) return 0; if (1ll*f[x][t]*s>n) return 0; if (Dfs (x+1,t,sta[x]*s)) return 1; } return 0;} int main () {Ios::sync_with_stdio (false); int t;cin>>t; jc[0]=1;for (int i=1;i<=12;++i) jc[i]=jc[i-1]*i; while (t--) {cin>>n>>k;top=0; if (jc[k]>n| | K>12) {puts ("NIE"); continue;} for (int i=1;i*i<=n;++i) if (n%i==0) {sta[++top]=i; if (i*i!=n) sta[++top]=n/i; } sort (sta+1,sta+1+top); for (int i=1;i<=top;++i) {long long t=1; for (int j=0;j<k&&i+j<=top;f[i][j++]=t) if (t>0) {t*=sta[i+j]; if (t>n) t=-1; }} puts (Dfs (1,k,1)? " TAK ":" NIE "); } return 0;}
[Pa2013]iloczyn