We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
AFAIK, there's no easy way to do this problem in C++ with the libraries provided. In real life you'd use a bignum library like GNU MP or Boost.Multiprecision, but those libraries aren't available here.
You can certainly roll your own, but that seems a little extreme.
I've done all the other algorithm problems in C++, but for this one I switched to Java so I could use java.math.BigInteger.
I passed all tests by using the Karatsuba multiplication algorithm with my own Big Integer implementation. Very dumb by the way, but fast enough to find the 24 modified Fibonacci number in a half of second (0 1 24).
Nothing special work was done about working with number representation – store it as is in a base 10 in a vector. If it is still relevant for you, email me (taenaru@gmail.com) and I'll gladly explain you how it might work.
It's a waste of dev time, imho. Karatsuba algo replaces 2mul+1add with 1mul+4add. They say mul takes 3-4 times cycles of add these days, so you gonna get max 12.5% speed up (or zero, if it's actually 3 times) for the code which probably takes less than 20% of execution time (memory access will be the bottleneck, not number crunching)
Fibonacci Modified
You are viewing a single comment's thread. Return to all comments →
can u pls explain how to handle big integer in c++.
AFAIK, there's no easy way to do this problem in C++ with the libraries provided. In real life you'd use a bignum library like GNU MP or Boost.Multiprecision, but those libraries aren't available here.
You can certainly roll your own, but that seems a little extreme.
I've done all the other algorithm problems in C++, but for this one I switched to Java so I could use java.math.BigInteger.
ohk.thank you
Here is how I do it. You can actually make it faster by playing with Base.
well done man
Please can you explain your code
I'm sorry, I got lost in the conversation, which code?
you are awesome man
include
include
include
include
int main() { int i=2,x,y,n; int z,a[100]={0}; scanf("%d %d %d",&x,&y,&n);
{ z=0; z=x+pow(y,2); x=y; y=z; i++; a[z]+=z; }
printf("%d",a[z]); return 0; }
this my code it is displaying segementation error can anyone help me in getting the actual bug in this code
I barely know a thing or two about that ostream operator,great work man!!
I passed all tests by using the Karatsuba multiplication algorithm with my own Big Integer implementation. Very dumb by the way, but fast enough to find the 24 modified Fibonacci number in a half of second (0 1 24). Nothing special work was done about working with number representation – store it as is in a base 10 in a vector. If it is still relevant for you, email me (taenaru@gmail.com) and I'll gladly explain you how it might work.
can you send me explaination
nickholden786@gmail.com
It's a waste of dev time, imho. Karatsuba algo replaces 2mul+1add with 1mul+4add. They say mul takes 3-4 times cycles of add these days, so you gonna get max 12.5% speed up (or zero, if it's actually 3 times) for the code which probably takes less than 20% of execution time (memory access will be the bottleneck, not number crunching)
No need for that young fella 🧐
JAVA SOLUTION
100% TEST CASES ✅
COMPLEXITY IN 0(N) TIME
but we have to return int value not string, so how we can do that
''' static BigInteger fibonacciModified(int t1, int t2, int n) { BigInteger[] arr = new BigInteger[n]; BigInteger tOne = new BigInteger(Integer.toString(t1)); BigInteger tTwo = new BigInteger(Integer.toString(t2)); arr[0] = tOne; arr[1] = tTwo; for(int i = 2; i < n; i++){ BigInteger iMinus1BigInteger = arr[i - 1]; BigInteger iMinus2BigInteger = arr[i - 2]; BigInteger powered = iMinus1BigInteger.pow(2); BigInteger poweredAndSum = powered.add(iMinus2BigInteger); arr[i] = poweredAndSum; }''' BigInteger result = arr[n-1];