#How do I do this?
21 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
@violet iris
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
!hw
Welcome to Together C & C++ :wave:
We won't do your homework for you (#rules) but we are happy to help you learn and point you in the right direction.
Please send what you have so far and ask a specific question.
and photos of the screen are the most useless thing ever
It’s not even a homework
There’s a club I joined today and they had a mini hackathon thing
And I didn’t know how to do this
The closest thing to this is howmeowrk
I mean this task is more on the math edge than programming per se, although such math tasks are popular in programming contests
if my mind serves me you need to have w = 2m + 2n where both m and n are natural, so w = 2(m + n), thus w itself has to be even, and additionally at least 4
because m and n need to be positive naturals, otherwise one of the children wouldn't get anything
So like the only numbers that would work are 4 and 8 and 12 etc…
No, because for example w = 6 could be divided into w_1 = 2 and w_2 = 4 which are both even and positive weights, so for w = 6 you would also need to output true
so the problem is asking if you can divide the weight of the watermelon in a way that both the two parts are even numbers ?
if my mind serves me you need to have
w = 2m + 2nwhere both m and n are natural
This doesn't make sense. You magically summon an identical second piece of watermelon slice for both the slices, so the result would be2w = 2m + 2n=>w = m + nwhich makes sense because the watermelon with weightwgets divided into two parts weighingmandnkilos.
Also interesting for @violet iris:
The solution really is very simple.
You need to realize that odd numbers won't work, so you can rule all of these out.
Then you look at the even numbers by just checking them one by one; you realize that for w = 2 you can't divide the watermelon into m and n with w = m + n and m, n > 0, so you know that for w = 2 it must be false.
You then look at w = 4 and realize that you can divide that into n = 2 = m.
You then look at w = 6 and see that n = 2, m = 4 works.
w = 8 => for example n = 2, m = 6.
w = 10 => for example n = 2, m = 8.
You realize that for every even number greater than 2 you can split that into n = 2 and m = w - n and since both w and n are even numbers (cause if w was odd we know it's false and we know n = 2) and the subtraction of two even numbers gives us an even number (which is also guaranteed to be positive in this case since we know that w > n).
To summarize it, we can really condense this into a nice little oneliner:
return (w > 2) * !(w & 1);
@plucky rune Aaaaand I just realized that you were saying exactly that and I just intially misread. Anyways, it's still a somewhat more in-depth explanation for OP so I figured it's useful
yes, indeed, that's exactly what I explained with simple math
¯_(ツ)_/¯
on the other hand "You need to realize that odd numbers won't work, so you can rule all of these out." isn't really explaining :P
there's also one smell here - !(w & 1) - compiler knows better how to optimize, you should write exactly what you have in mind instead of being too smart :P