10766 - Organising the Organisation

All about problems in Volume 107. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden

Post 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. :)
..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post 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??
My signature:
  • Please make discussion about the algorithm BRFORE posting source code.
    We can learn much more in discussion than reading source code.
  • I HATE testing account.
  • Don't send me source code for debug.
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post 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...
Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden

Post 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).
Cho
A great helper
Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong

Post 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?
Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden

Post by Per »

One can use a simple double-and-add algorithm for multiplication (analogous to square-and-multiply for exponentiation).
Post Reply

Return to “Volume 107 (10700-10799)”