标签:
Description
Peter has just learned mathematics. He learned how to add, and how to multiply. The fact that 2 + 2 = 2 × 2 has amazed him greatly. Now he wants find more such examples. Peters calls a collection of numbers beautiful if the product of the numbers in it is equal to their sum.
For example, the collections {2, 2}, {5}, {1, 2, 3} are beautiful, but {2, 3} is not.
Given n, Peter wants to find the number of beautiful collections with n numbers. Help him!
Input
Output
Sample Input
2 5
Sample Output
1 3
Hint
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<algorithm> #include<queue> #include<vector> #include<stack> using namespace std; int n,ans; void dfs(int x,int k,int product,int sum) { for(int i=x;i>=2;i--) { if(product*i>sum+i+n-k) continue; else if(product*i==sum+i+n-k) ans++; else dfs(i,k+1,product*i,sum+i); } } int main() { scanf("%d",&n); dfs(n,1,1,0); printf("%d\n",ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4433959.html