|
|
вернуться в форумHELP WITH IDEA!!! Who has accepted this task, please help with idea. I have not anithing idea! Re: HELP WITH IDEA!!! Послано svr 3 мар 2008 13:43 Use log10 to compare 2^n and 10^k Re: HELP WITH IDEA!!! 2 svr: I don't understand what you mean ? What I should use formule or ...? Re: HELP WITH IDEA!!! 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!!! Thanks a lot!!! Re: HELP WITH IDEA!!! 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!!! Послано svr 3 мар 2008 20:45 I meant the formula a[n]=2/3+(-1)^(n-1)/(3*2^(n-1)) Re: HELP WITH IDEA!!! Послано vgu 5 мар 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!!! we should take log10 from abs(2/3-a[n]) ?? Re: HELP WITH IDEA!!! Послано svr 5 мар 2008 10:16 use also the formula: 2/3=0.666666+10^(-k)*2/3 Re: HELP WITH IDEA!!! 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. */ |
|
|