[Pa2013] Iloczyn

Source: Internet
Author: User

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\)

      Analytical

      This 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&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.