+ 6
The parameters in binpow are defined as long. The highest bit that you can store in a is bit63 (2^63). If b is larger than 63, then a becomes 0 and stays at 0 thereafter.
8th May 2022, 5:17 PM
Brian
Brian - avatar
+ 5
Well Brian ... Nice to meet you then ... I guess? 😂 edit: I said that but it depends how much of an expert you are looking for! I am confortable and quite good, but nowhere near an expert for more than one reason! the first one being that I stopped at C++14 edit 2 : you can look at some of my codes to decide by yourself, the ones I am the most proud of here are the compile time algorithms
8th May 2022, 6:34 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 4
Brian the article you shared state a complexity of O(n*log(n)) which is equivalent to the most efficient complexity of sorting an array so... I guess it's basically an array manipulation! I suppose the compulator can't do some manipulations to guess because it can't guess the size of the data the BigInt will contain as it can be runtime dependent
9th May 2022, 8:50 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
It's just one of those things that you tuck away in your toolbox in case you might need it. 🧰
8th May 2022, 5:51 PM
Brian
Brian - avatar
+ 2
Brian Python and Ruby are using BigInt, every operations on those numbers is not a trivial one so even the binary shift is more likely an array manipulation
8th May 2022, 6:41 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 2
Hi Baptiste E. Prunier. In my career I have developed in C++ on large teams for major corporations with people whom I consider experts in C++, but they all admitted that they are not comfortable with it. In larger teams it gets harder to read other people's code, as you have to mentally review so many rules and actively verify that they know what they are doing while you try to comprehend whether it is valid. C++ is mentally taxing!
8th May 2022, 6:55 PM
Brian
Brian - avatar
+ 1
Ash[I Wish To See You Free One Life] besides using float? Yes. Look into using the BigInt class. Unfortunately, I cannot guide you in that, as I have never needed to use it.
8th May 2022, 5:31 PM
Brian
Brian - avatar
+ 1
Candidly, I am not excited about C++ either. Too many rules! I like the simplicity of C. I have never met anyone who feels comfortable programming in C++.
8th May 2022, 5:58 PM
Brian
Brian - avatar
+ 1
I never looked at Ruby code before, but I am finding that Sololearn won't even output all of the results of puts 1<<1000000 The only thing faster than a binary shift would be to determine the answer before writing the program and print it as a constant. Even then it seems likely that Sololearn would proclaim TLE error.
8th May 2022, 6:27 PM
Brian
Brian - avatar
+ 1
FYI, I tried it in Python and got the exact same result - TLE at the very same cutoff point.
8th May 2022, 6:31 PM
Brian
Brian - avatar
+ 1
If the compiler is as efficient as it should be, a binary shift would be orders of magnitude times faster.
8th May 2022, 6:38 PM
Brian
Brian - avatar
+ 1
Ash[I Wish To See You Free One Life] I didn't understand your last message 😂 do you mean that we can only be serious? 🤔
8th May 2022, 6:44 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
Side topic: there was a somewhat recent development in efficient multiplication of big integers: https://www.sololearn.com/post/88511/?ref=app
8th May 2022, 7:09 PM
Brian
Brian - avatar
+ 1
Of course BigInt would take longer to shift than an intrinsic integer, but after compiler optimization I imagine that the shift expression is easily transformed into a constant assignment that is likely faster than operations that involve successive multiplications.
9th May 2022, 1:18 PM
Brian
Brian - avatar