The original title
Topic analysis
By know the meaning of problems, X each time only a qualitative factor decomposition to obtain the longest chain. 2 as 20 = 2 * 5 = (2 * 5,5,1) is a factor of 20 the longest chain. Thus the longest chain length factor equal to the quality factor and the power combining method. longest chain is apparent from a combination of factors mathematics (full array and the powers of prime factors) / (mass per the whole arrangement of a power factor) species. of topic data shows a process of solving mathematical combination does not burst longlong, so no additional processing.
Code
1 #include <cstdio> 2 #include <cstdlib> 3 #include <iostream> 4 #include <algorithm> 5 #include <utility> 6 #include <ctime> 7 #include <cmath> 8 #include <cstring> 9 #include <string> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <set> 14 #include <map> 15 16 using namespace std; 17 typedef long long LL; 18 const int INF_INT=0x3f3f3f3f; 19 const LL INF_LL=0x3f3f3f3f3f3f3f3f; 20 21 LL factorial[21]; 22 bool is_prime[10000]; 23 int prime[10000]; 24 int cnt; 25 int num[10000]; 26 int k; 27 28 void pre() 29 { 30 factorial[0]=factorial[1]=1; 31 for(int i=2;i<=20;i++) factorial[i]=factorial[i-1]*i; 32 for(int i=2;i<=9000;i++) is_prime[i]=true; 33 for(int i=2;i<=9000;i++) 34 { 35 if(is_prime[i]) 36 { 37 prime[cnt++]=i; 38 for(int j=(i<<1);j<=9000;j+=i) is_prime[j]=false; 39 } 40 } 41 } 42 43 void prime_factor(int x) 44 { 45 k=0,num[k]=0; 46 LL sum=0; 47 for(int i=0;i<cnt;i++) 48 { 49 while(!(x%prime[i])) x/=prime[i],num[k]++; 50 sum+=num[k]; 51 k++,num[k]=0; 52 } 53 if(x!=1) sum++; 54 printf("%lld ",sum); 55 sum=factorial[sum]; 56 for(int i=0;i<k;i++) sum/=factorial[num[i]]; 57 printf("%lld\n",sum); 58 } 59 60 int main() 61 { 62 // freopen("black.in","r",stdin); 63 // freopen("black.out","w",stdout); 64 pre(); 65 int x; 66 while(~scanf("%d",&x)) prime_factor(x); 67 return 0; 68 }