Sort by

recency

|

724 Discussions

|

  • + 0 comments

    Here is my Python solution!

    def fibonacciModified(t1, t2, n):
        sys.set_int_max_str_digits(99999999)
        first = t1
        second = t2
        for i in range(n - 2):
            current = first + second ** 2
            first = second
            second = current
        return current
    
  • + 0 comments

    Java:

    public static BigInteger fibonacciModified(int t1, int t2, int n) {
        BigInteger n2 = BigInteger.valueOf(t1), n1 = BigInteger.valueOf(t2), fib = BigInteger.ZERO;
        if (n == 1) {
            return n2;
        }
        if (n == 2) {
            return n1;
        }
        for (int i=3; i <=n; ++i) {
            fib = n2.add(n1.multiply(n1));
            n2 = n1;
            n1 = fib;
        }
        return fib;
    }
    
  • + 1 comment
    def fibonacciModified(t1, t2, n):
        for _ in range(n-2):
            t1=t1+t2**2
            t1^=t2
            t2^=t1
            t1^=t2
        return t2
    
  • + 0 comments

    For the solution in java, the method definition should be modified to BigInteger, else it won't work for big numbers.

  • + 0 comments

    Looking for an epic desert experience? Check it out at Dune Buggy Dubai and discover the adventure of a lifetime! Check it out the exciting buggy rides that are safe, fun, and perfect for all adventure seekers.