Project Euler #235: An Arithmetic Geometric sequence

Sort by

recency

|

40 Discussions

|

  • + 0 comments

    I'm confused as to why I can only complete half of the test cases

    from copy import deepcopy
    
    def arGeoSeq(a1,d1,k1,r1):
        return (a1-d1*k1)*r1**(k1-1)
    
    def arGeoSeqDer(a1,d1,k1,r1):
        if(k1 == 1):
          return 0
        else:
          return (k1-1)*(a1-d1*k1)*r1**(k1-2)
            
    def arGeoSer(a2,d2,n2,r2):
        res = 0
        for i in range(1,n2+1):
            res += arGeoSeq(a2,d2,i,r2)
        return res
    
    def arGeoSerDer(a2,d2,n2,r2):
        res = 0
        for i in range(1,n2+1):
            res += arGeoSeqDer(a2,d2,i,r2)
        return res
        
    q = int(input())
    for i in range(q):
        temp = input().split(' ')
        a, d, n, x = int(temp[0]), int(temp[1]), int(temp[2]),int(temp[3])
        r = 1
        counter = 0
        while(True):
            temp = deepcopy(r)
            fx = arGeoSer(a,d,n,r) + x
            fxDer = arGeoSerDer(a,d,n,r) + x
            # print(counter,r,fx,fxDer)
            r = r - fx/fxDer
            if(r == temp):
                break
            counter += 1
        print(r)
    
  • + 0 comments

    why is this not allowing me to use numpy ?

  • + 0 comments

    Newton Raphson method is giving timeout error for 3 testcases. Is there any method that converges faster than Newton's method?

  • + 0 comments

    Why is my code giving EOF error everytime? It is running fine in PyCharm but not here.

  • + 0 comments

    Hi, I get 1.0013652149550007 for the test case 0 but it is denied by the test case