|
|
|
|
|
by yobbo
1481 days ago
|
|
It's a quiz problem, and it's supposed to have "trick" solutions. However, if he wants to play that game, he should provide proof of his solution, not fiddle with syntax or error checking. That's why discussion is more important, and how he can show that understands what he's doing and not just memorizing tricks. (... none of which matters for his future role anyway.) The formula "falls out" naturally if you're used to working with summations: Σi = Σ(n-i+1) = n² - Σi + n 2Σi = n² + n ... but the xor solution is more elegant. |
|
So I opened the python interpreter, and I used this very trivial method of calculation (instead of summing the sine and cosine functions independently), and using asin and acos functions, got the result. It turned out to be accurate for n=1e6 with an error of ~1e-5. So it should be usable for much bigger n too.