Just in case:
Fib(0) = 0
Fib(1) = 1
Fib(2) = 1
Fib(3) = 2
is currently used in this challenge. Just had a example in my python book about iterations using fibonacci sequence, so i modified it 'slightly' (~5min sounds about right, running it on one core only)
Big Fib
-
- Posts: 35
- Joined: Tue May 12, 2009 6:08 pm
- Location: Greece
If you have struggled with this one, what will you do with "Biggest Fib"?speedfire wrote:Oki finally I done it.
I have code a program with a logarithmic algorithme.
But for real... Do you really think everyone are mathematician ?
If you don't know anything about optimisation good luck ! You can wait a long long long time If you don't code proprely.
Anyway you are on "hacker.org", this means you are supposed to tackle problems in a smart way.
Good luck!
Why not use some tools?
Is using math software considered cheating? I was amazed how quickly maple calculated the fib number (using the closed-form solution, I guess).
-
- Forum Admin
- Posts: 496
- Joined: Sat May 28, 2011 9:14 am
- Location: Germany
Re: Why not use some tools?
Of course not.gowron wrote:Is using math software considered cheating?
-
- Posts: 35
- Joined: Tue May 12, 2009 6:08 pm
- Location: Greece
Re: Why not use some tools?
Cheating? haha You are supposed to cheat if u can!gowron wrote:Is using math software considered cheating? I was amazed how quickly maple calculated the fib number (using the closed-form solution, I guess).
// F_1=1, F_2=1, F_n=F_{n-1}+F_{N-2};
// I tend to use Java.math.BigInteger when cope with big numbers, and it's handy.
import java.math.BigInteger;
public class Hacker144
{
private static final int INDEX = 1500000;
private static final int STEP = 20000;
public static void main(String args[])
{
BigInteger f1 = new BigInteger("1");
BigInteger f2 = new BigInteger("1");
for(long i = 1; i < INDEX; ++i)
{
BigInteger tmp = f2;
f2 = f2.add(f1);
f1 = tmp;
}
final String ans = f1.toString();
for(int i = 0; i < ans.length(); i += STEP)
System.out.print(ans.charAt(i));
}
}
// I tend to use Java.math.BigInteger when cope with big numbers, and it's handy.
import java.math.BigInteger;
public class Hacker144
{
private static final int INDEX = 1500000;
private static final int STEP = 20000;
public static void main(String args[])
{
BigInteger f1 = new BigInteger("1");
BigInteger f2 = new BigInteger("1");
for(long i = 1; i < INDEX; ++i)
{
BigInteger tmp = f2;
f2 = f2.add(f1);
f1 = tmp;
}
final String ans = f1.toString();
for(int i = 0; i < ans.length(); i += STEP)
System.out.print(ans.charAt(i));
}
}
/* Life runs on code */