Page 1 of 3
11087 - Divisibility Testing
Posted: Sat Sep 09, 2006 8:34 pm
by Martin Macko
To help people who have troubles with this problem, note, that the answer doesn't have to fit to 32bit integer (as the answer may be as big as
10^
5*(
10^
5-
1)/
2). My other bug was, that at first I didn't realise that
-7%
4=
-3 a not
1.

Posted: Sat Sep 09, 2006 8:47 pm
by Adrian Kuegel
It seems there is no input where the output doesn't fit in a 32 bit integer.
At least under the assumption that you got accepted with long long. I got accepted with int.
Posted: Sat Sep 09, 2006 8:55 pm
by Martin Macko
Adrian Kuegel wrote:It seems there is no input where the output doesn't fit in a 32 bit integer.
At least under the assumption that you got accepted with long long. I got accepted with int.
Well, I've corrected both bugs at once, so possibly there are be no such inputs in the judge. Anyway, the constraints allow such inputs.
Posted: Sun Sep 10, 2006 3:54 am
by Hisoka
why n lg n algo get TLE > 10 s ? since T < 100 and n < 100001 ?
thanks
Posted: Sun Sep 10, 2006 4:51 am
by Hurricane_NET
A program with complexity O(NlogN) and a relatively small constant factor will run well within the time limit...
Posted: Sun Sep 10, 2006 7:38 am
by sakhassan
Can neone give me some test cases which r critical ??
Posted: Sun Sep 10, 2006 8:01 am
by Sumon
Hisoka wrote:why n lg n algo get TLE > 10 s ? since T < 100 and n < 100001 ?
thanks
Your program's worst case complexity = T*nlgn*C = 100*(lg100000)*100000*C=1.7*10^8*C,where C is cost of unit operation in each iteration. If this C is larger then there is no way of running within the time limit. I think this problem is not solvable with nlogn algo. I got accepted it with 2*n+K,where K is a small number and it took 7.141 Sec. So, you can compare your's complexity with mine to get the concept about the time required by your algo.
Posted: Sun Sep 10, 2006 1:41 pm
by Hisoka
Ouu, ic ... You can doing 2 N + K algo without sorting before ...
Thanks
Posted: Sun Sep 10, 2006 3:23 pm
by sunny
can u pls describe ur algo a little bit.
Posted: Sun Sep 10, 2006 3:25 pm
by Martin Macko
Hisoka wrote:Ouu, ic ... You can doing 2 N + K algo without sorting before ...
Thanks
My algo sorts the numbers at the beginning and runs in about 8.7s.
Posted: Sun Sep 10, 2006 4:22 pm
by little joey
The real time bottle-neck is not the sorting of the input, but the reading of it in the first place.
My first attempt, using scanf() to read the input and using qsort() to sort it, took 5.5 seconds to read and 4.0 seconds to sort all of the judge input.
I feel sorry for Darko and all others that try to solve this problem in Java...
Posted: Mon Sep 11, 2006 2:36 am
by sclo
The only reason for sorting is to identify the duplicates, there are ways to do it without sorting.
Posted: Mon Sep 11, 2006 2:04 pm
by vinay
some hints please.......

Posted: Mon Sep 11, 2006 5:24 pm
by Hadi
Only thing other than sorting that comes to my mind is Hashing. But I get WA with hashing. (I cannot use perfect hashing, i.e. a + 10000000 because I get TLE) , so I use a % some_prime_less_than_8000000).
Any suggestions?
Posted: Tue Sep 12, 2006 12:18 am
by sclo
hashing with a prime less than 10^6, with linked list resolving the collisions should work fine.