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

Show all messages Hide all messages

is java's BigDecimal acceptable? Faeton (Kyiv - Mohyla Academy) 6 Mar 2008 16:17
I solve reccurence, then pow to n(which takes log n to quickpow), but it's also TL.

How can i improve this not writing my own long arithmetic?
Re: is java's BigDecimal acceptable? elmariachi1414 (TNU) 29 Mar 2008 01:21
It can be solved only with 2 divisions in BigDecimal, but answer length is about 32000 so [maybe] toString gives TLE on conversion binary data to decimal representation.
If somebody knows, how to solve this problem - please tell me
2^n = 10^(n*lg(2))
My AC solution:
int n0 = (int) (Math.log10(2f) * (n - 1));
int n1 = (int) (Math.log10(2f) * n);
int n2 = (int) (Math.log10(2f) * (n + 1));
int len = n1;
if (n1 == n2 && n1 == n0 + 1 && n % 2 != 0) {
  len = n0;
}

Answer is len.
Re: is java's BigDecimal acceptable? freedevc 4 Nov 2008 17:57
I thought that this problem's solution is :

t= (n-(n%10)) /4 +1
if(n>=30)
{
        t=t+1;
        x=n-n%10;
        if(n>39&&((x/10)%2)) t=t+(x-30)/20;
        if(n>49&&((n-n%10)%4==0)) t=t+(x-40)/20;
}
t= t+ (n%10)/4;
cout<<t;

but it got WA#8.

And i don't understand "if(n==1 && n1==n0+1 && n%2!=0)" statement are for what tests?
Would you mind explaining for me! Thanks!
Re: is java's BigDecimal acceptable? Artem Khizha [DNU] 31 Oct 2010 23:24
bve, your way is brilliant.
Thank you!
Re: is java's BigDecimal acceptable? balatskayaolha 20 Feb 2020 21:30
Thanks you!
Re: is java's BigDecimal acceptable? exwRabbits_AlMag(VNTU) 18 Feb 2020 04:27
bve, any links to why it works?