Hi all,
I'm getting tle. Here is my process that i applied.
1. Generate all prime factors upto 2000000 and store them.
2. Then get the value n and iterate to find out the result, sort and print them.
My question is, is this problem solvable by easy way ?? I think i make the problem more complex. Is there any way to generate all the values in non-decreasing order ?? Any idea or sugesstion ??? Thanx in advance.
10858 - Unique Factorization
Moderator: Board moderators
Re: 10858 Unique Factorization
it seems very strange, but you don't have to generate prime factors, i use simple algo, it looks like this:Chok wrote:Hi all,
I'm getting tle. Here is my process that i applied.
1. Generate all prime factors upto 2000000 and store them.
2. Then get the value n and iterate to find out the result, sort and print them.
My question is, is this problem solvable by easy way ?? I think i make the problem more complex. Is there any way to generate all the values in non-decreasing order ?? Any idea or sugesstion ??? Thanx in advance.
void generate(int number,int lastdivisor) {
if(number==1)
print stack;
else
for all numbers p from lastdivisor to sqrt(number)
check if number%p==0 {
add to stack p
generate(number/p,p);
delete p from stack
}
}
where stack is a structure where you can store actuall divisors
ofcourse it is not a full algo, but only idea [fast - acc in 0.072 in pascal]
hope it helps, if i wrote something wrong please correct me
![:D](./images/smilies/icon_biggrin.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10858 - Unique Factorization
Input:AC output:
Code: Select all
24
0
Code: Select all
6
2 2 2 3
2 2 6
2 3 4
2 12
3 8
4 6
Check input and AC output for thousands of problems on uDebug!