Lessons learned from solving weirdo (as well as solution)

You don’t need power, just three basic log properties

log(a^b) = b*log(a)

log(a/b)= log(a) - log(b)

log(a*b)= log(a) + log(b)

Use them on the expression to get it into a one line formula which doesn’t need powers but logarithms

3 Likes

Fantastic. I studied it in detail. From a debug perspective, can you explain the purpose of assert(cin) in the last line?

1 Like

It’s just to ensure that I haven’t accidentally tried to read more input than exists, or e.g. tried to read a string as an int or somesuch - something that has bitten me a few times in the past :slight_smile:

Edit:

Also helps to make sure that my testcase generator generates the right amount of stuff and of the right type.

3 Likes

Thanks for the explanation! Would you mind if I mimic some elements of your style, since emulation is the highest form of adulation! :slight_smile:

1 Like

I would be honoured :slight_smile: Please take anything you want :slight_smile:

Edit:

I gabbled on about my process here, and included the code template I usually use. Bear in mind that I don’t do short contests, though - the process really wouldn’t be suitable for those :slight_smile:

1 Like

Fantastic. Good practices to be learnt!

1 Like