Page 2 of 2

Posted: Wed Dec 15, 2004 11:53 am
by Per
It is a small mistake from my side that the problem is solvable using long doubles, I never thought to make sure that that wouldn't work. Bigints are highly likely to give you TLE, and regular doubles have no way of handling the precision required.

But anyway, all ways that work are good ways. :)

Posted: Wed Dec 15, 2004 12:19 pm
by ..
Hi Per, I used long double because I have no idea how to solve it using integer arithmetic. I have considered using Chinese Remainder Theorem(as Cho said in previous post) + BigInt to solve this problem, but it is too troublesome. (In the other way, I am too lazy :wink: )
May I know what is the expected approach to solve the problem??

Posted: Wed Dec 15, 2004 1:01 pm
by little joey
An "infinite precision" rational number class (analogus to a bigint class for natural numbers) would solve this problem without the "hope and pray" imprecision of (long) doubles. But there is no problem in the set (AFAIK) that requires it, so I haven't got one yet. Guess I'm too lazy to make one without the nessecity of using it in a program...

Posted: Wed Dec 15, 2004 5:31 pm
by Per
My "intended" solution was to compute the answer modulo a prime bigger than 10^15. There is no need for CRT or BigInts, just regular modular arithmetic (including inverse).

A rational-based solution would probably get TLE (or well, at least the one I wrote is way too slow).

Posted: Wed Dec 15, 2004 5:40 pm
by Cho
But the multiplication (involved during computing the determinant modulo a prime bigger than 10^15) could exceed the limit of long long before you do the modulation.
How could you handle that?

Posted: Wed Dec 15, 2004 5:42 pm
by Per
One can use a simple double-and-add algorithm for multiplication (analogous to square-and-multiply for exponentiation).