C-sum vs ProductTime
limit:1000MS
Memory Limit:64000KB
64bit IO Format:%lld &%llu< /c7> SubmitStatusPracticeAcdream 1431Appoint Description:System Crawler (2015-04-16)
Description
Peter has just learned mathematics. He learned how to add, and what to multiply. The fact that 2 + 2 = 2x2 have 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 was equal to their sum.
For example, the collections {2, 2}, {5}, {1, 2, 3} were beautiful, but {2, 3} was not.
Given N, Peter wants to find the number of beautiful collections with n numbers. Help him!
Input
The first line of the input file contains n (2≤n≤500)
Output
Output one number-the number of the beautiful collections with n numbers.
Sample Input
25
Sample Output
13
Hint
The collections in the last example is: {1, 1, 1, 2, 5}, {1, 1, 1, 3, 3} and {1, 1, 2, 2, 2}.
#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;}
DFS Acdrean 1431