ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1605. Devil's Sequence

HELP WITH IDEA!!!
Posted by Nurbek_[KTMU MANAS] 3 Mar 2008 13:33
Who has accepted this task, please help with idea.
I have not anithing idea!
Re: HELP WITH IDEA!!!
Posted by svr 3 Mar 2008 13:43
Use log10 to compare 2^n and 10^k
Re: HELP WITH IDEA!!!
Posted by Nurbek_[KTMU MANAS] 3 Mar 2008 13:53
2 svr: I don't understand what you mean ? What I should use
formule or ...?
Re: HELP WITH IDEA!!!
Posted by alex zaharov 3 Mar 2008 14:14
This sequence representable in the form of partial sums apparent number, the amount of which is equal to 1 / 6 - to find the desired response should compare the full amount of partial, asked n. only math.
--
по-русски:
эта последовательность представима в виде частичных сумм очевидного ряда, сумма которого равна 2/3 - чтобы найти искомый ответ необходимо сравнить всю сумму с частичной, задаваемой n. чистая математика.
Re: HELP WITH IDEA!!!
Posted by Nurbek_[KTMU MANAS] 3 Mar 2008 16:06
Thanks a lot!!!
Re: HELP WITH IDEA!!!
Posted by Vedernikoff Sergey 3 Mar 2008 16:31
I've accepted this problem using precalc. Just quick long arithmetics and some trick to make source file of size 4 Kb...
Re: HELP WITH IDEA!!!
Posted by svr 3 Mar 2008 20:45
I meant the formula
a[n]=2/3+(-1)^(n-1)/(3*2^(n-1))
Re: HELP WITH IDEA!!!
Posted by vgu 5 Mar 2008 02:27
to svr:
you are right, this formula is correct (I can prove it).
But how to take benefit from this?
Of course, using this this formula I can right brute force quick long arithmetics. But this algo will be TL.
Re: HELP WITH IDEA!!!
Posted by KIRILL(ArcSTUpid coder:) 5 Mar 2008 03:07
we should take log10 from abs(2/3-a[n]) ??
Re: HELP WITH IDEA!!!
Posted by svr 5 Mar 2008 10:16
use also the formula:
2/3=0.666666+10^(-k)*2/3
Re: HELP WITH IDEA!!!
Posted by SkorKNURE 29 Oct 2010 05:38
I think problem is very interesting. I was trying to solve it in "programming way" for a long time, but all my attempts lead to TL on N > 10000 values. Finally I finished with completely mathematical solution. I think that description from my source can help someone so I'll left it here...

/*
 * Let x[n] be n-th element of given sequence.
 * Following formula for x[n] can be simply proved:
 *    x[n] = 2/3 + (1/3)/(2^(n-1)) if n - odd
 *    x[n] = 2/3 - (1/3)/(2^(n-1)) if n - even
 * Let delta = (1/3)/(2^(n-1)) = 0.000XXXX.. (X - any digit)
 * We can simply find number of leading zeroes after
 * decimal point (befor XXX..) as:
 *    k = floor[ Log10(3*2^(n-1)) ] or
 *    k = floor[ Log10(3) + (n-1)*Log10(2) ]
 * Obviously answer always will be k or k-1.
 * Consider (k-1)-cases:
 * [1] N - odd (add delta):
 *     A = (1/3)/(10^k) = 0.0003333... (repeat 0 k times)
 *     If A <= delta - then addition will affect k-th digit
 *     and answer will be k-1.
 * [2] N - even (subtract delta):
 *     A = (2/3)/(10^k) = 0.0006666... (repeat 0 k times)
 *     If A <= delta - then subtraction will affect k-th digit
 *     and answer will be k-1.
 * Compare logarithms instead of comparing values themself.
 */