Title Description
A positive integer greater than 1 n can be decomposed into: N=X1*X2*...*XM.
For example, when n=12, there are 8 different types of decomposition:
12=12;
12=6*2;
12=4*3;
12=3*4;
12=3*2*2;
12=2*6;
12=2*3*2;
12=2*2*3.
For a given positive integer n, there are a number of different decomposition types for programming n. Input
The first row of each set of test data has 1 positive integer n (n<=10^10). Output
Will calculate the different number of exploded output. Sample input
12
Sample output
8
If you use a search, you need to use a memory search, save with a map, and then optimize to sqrt (n)
can be begged out.
Another kind of dynamic programming,
12 of the factors are
1 2 3 4 6 12
1 1 1 2 3 8
Then you just need to decompose the factor on the line.
#include <stdio.h>
#include <map>
using namespace std;
Map < int, int > vis;
int dfs (int n)
{
if (n = = 1)
return 1;
if (Vis[n]) //Search over
return vis[n];
int s = 1;
for (int i = 2; i*i <= N; i + +) //optimized to SQRT (n)
if (n%i = = 0)//factor
{
s = S+dfs (i);
if (i! = n/i)//Unequal search for the next layer
s = S+dfs (n/i);
}
Vis[n] = s;
return s;
}
int main ()
{
int n;
scanf ("%d", &n);
printf ("%d", DFS (n));
return 0;
}