I don't want to copy answers but I don't know how to complete my homework
因式分解(Factor deconstruct)
描述:(Description)
输入一个整数N,求所有因子相乘的情况。(从大到小)(Input a whole number,get the product of all factors(?))
输入:(Input)
一个整数N(whole number N)
输出:(Output)
所有因子相乘的情况(product of all factors(??))
难度:(Difficulty)
A
输入示例:(Input example)
20
输出示例:(Output example)
20=20*1
20=10*2*1
20=5*4*1
20=5*2*2*1
20=4*5*1
20=2*10*1
20=2*5*2*1
20=2*2*5*1
代码类型:(code type)
C/C++
Im confused on prime factoring and non-prime factoring(???)
I did this in Snap quickly (haven't had time to fully think about it but this seems like the general algorithm you'd want to take). Basically you can decompose any number into a series of prime numbers so for 99 we can rewrite it as 3x3x11. We can use the fact that 2 is the only even prime number to our advantage and then only divide by odd numbers from there to find the rest of our prime factors
Edit: Since C/C++ syntax is different this shouldn't be too easy to direct copy to your HW but a helpful start on the general mathematical concept.
Okay, so, 1×n is a special case and you just count that separately. Otherwise, you look for factors from 2 to n-1. So you discover that 2 is a factor of 20, and 20/2 = 10. Great, now you recursively find all the factorizations of 10, and stick "2×" in front.
The reason you have to treat 1 specially is that you don't want, e.g.,
20 = 20×1×1×1×1×1
as a factorization, because if you allowed those there would clearly be infinitely many factorizations.
But since you talk about combinations, it sounds to me as if they just want to to count the factorizations, not to display them all. I'm not sure what you've already learned in this course, but you should be able to take a recurrence relation like
$$f(n) = \sum_{i \in {\rm factors\ of}\ n} f(n/i)$$
and get a closed form expression for $$f(n)$$. (I left out the base case of the recurrence because it's too late at night for me to hassle with TeX. I'm proud of myself for getting spaces in "factors of n.")
Oh I see.
its just a tinkered combination function.
but i already figured it out myself bc i forgot that there was something like"snap forums" on the past 11 days -_-
Ok, I'll make sure, but i've tried it before on a javascript program which said 4 is prime. But i'll try it again.
EDIT: I tried it again and it said it isn't prime. Even with the irrational sqrt.