Factorizing

Stuff about math!

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.

No.It is something related to combinations I think.
Also:

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 -_-

That's not very Snap! ly.

The RESHAPE block is a little exotic. In this case it means
(HOW MANY TIMES...) COPIES OF (ID OF ( ))

I was just wanting to use these but I'm having a problem with the how many times reporter

I was expecting 2 as the answer on the basis that 2 x 2 x 3 = 12
aoc23Day8 script pic

Is the block wrong or am I interpreting the answer incorrectly?

You probably made a faulty copy. I got AoC 2023 day 5 script pic (10)

Ta

Brian's image says this

but yours says
image

so that explains the discrepancy :slight_smile:

So it was actually me who made the “faulty” copy. :smirk:
I guess @bh would call it a mis-feature, or something.

Serendipity :slight_smile:

The final prime factorisation is now failing me as well

aoc23Day8 script pic (5)

I was expecting [2,2,3]
Have I mis-typed this one?

[edit] I wonder if it's down to recent change in the reshape reporter?

[edit2] No - its down to issue with how many times reporter again - it's saying 3 is used as a factor of 12 three times!

aoc23Day8 script pic (3)

[Edit 3] #LOL and now Brian's works (as it of course it should when you follow the rabbit down the recursive hole) :slight_smile:

image

aoc23Day8 script pic (6)

aoc23Day8 script pic (7)

aoc23Day8 script pic (8)

I can now get back to the problem that I wanted this block for :slight_smile:

@18001767679
@bhenrique
I found a simpler way on a python tutorial, and here's what I got from it:




And bh, please don't say

It's the most simple way i could think of.

Sorry, I didn't mean to discourage you! Mea culpa.

But I do have a small suggestion: Instead of stopping at n/2 you can stop at √n.

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.

I guess you have to say ceil(sqrt(n)).