Hi,
I've read that there's a closed formula for this problem.. and it shouldn't be too hard since there're many people solved it during the contest..
So.. any hint about the formula? I've thought about this problem for few days but no results..
For me, it seems that this problem is more difficult than calculating n-th harmonic number and calculating n!, of which to the best of my knowledge, there's no closed formula...
Thanks.
11250 - Working with Small Numbers
Moderator: Board moderators
Well, the formula for 1/(k(k+1)) should've been standard knowledge and this problem is just an extension.
I think it has to be of the following forms:
A + 1/(B(n+1)(n+2)...(n+k)) where k+1 is the number of factors in the denominator of the summand.
The problem here is getting tle for no obvious reason. I had to make weird optimizations to get AC in more than 9.3 secs.
I think it has to be of the following forms:
A + 1/(B(n+1)(n+2)...(n+k)) where k+1 is the number of factors in the denominator of the summand.
The problem here is getting tle for no obvious reason. I had to make weird optimizations to get AC in more than 9.3 secs.
I am not sure if it is your gcd/division implementation, or maybe the way you are multiplying it. My sum for [1,n] is something like A/(C1*(A+C2)), where A=f(n) and C1,C2 are constants (and A is "nice"). Before I multiply two sums, I reduce the fractions, maybe you don't?sclo wrote: The problem here is getting tle for no obvious reason. I had to make weird optimizations to get AC in more than 9.3 secs.
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
By choosing the proper order of calculations, you never have to multiply two bigints or divide one by an other. Instead you only need multiplication of a bigint by a regular int and division by a regular int. This can save lots of time. (This under the assumption that the base of your bigints is >1000000003).sclo wrote:The problem here is getting tle for no obvious reason. I had to make weird optimizations to get AC in more than 9.3 secs.
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.