Project Euler #197: Investigating the behaviour of a recursively defined sequence

Sort by

recency

|

20 Discussions

|

  • + 0 comments

    This worked for me, it doesn't require 10^12 iterations: My implementation-

    cin >>u0>>b;
    //double a = reccur(1000000);
    
    double f_val = u0;
    double pf_val;
    for(unsigned long long i=1;i<=1000001; i++){
        pf_val = f_val;
        f_val = fn_1(pf_val);
        if(f_val == pf_val)
        break;
    
    }
    //double b = fn_1(f_val);
    cout<<setprecision(16)<<f_val + pf_val;
    return 0;
    
  • + 1 comment

    The series may not only be converging, but periodic.

  • + 1 comment

    This code passes for test0 and fails fro all of others I didn't understand the reason.

    import math 
    
    un, b = map(int, input().split() )
    
    def function(x,b): 
            return math.floor(2**(b-x**2))*10**(-9) 
    
    for _ in range(10**5):
            un1 = un
            un = function( un1, b)
    
    print(un + un1)
    
  • + 1 comment

    import math def dp(b, start_val): array = [0]150 array[0] = start_val i=0 while i<=148: array[i+1] = math.floor(2*(b-array[i]2)) * 10(-9) if(array[i+1] == array[i]): break i+=1

    print (array[i] + array[i-1])
    

    ub = input().split() u0 = float(ub[0]) b = float(ub[1]) start_val = math.floor(2**(b-u0**2)) * 10**(-9) dp(b, start_val)

    passed all test cases. Cheers!!!

  • + 0 comments

    f(Un)=L when n --->+oo

    And we have f(Un)=Un+1 so f(Un)=Un+1=L when n--->+oo

    meaning that Un become constant when n is big , so we just need to calculate Un and Un+1 when n =1e5 , but if the error is for example 1e-18 we may need to put n=1e6 or more.