Java, 165 bytes
Golfed:
BigInteger f(int n){BigInteger[]a={BigInteger.ZERO,BigInteger.ONE,BigInteger.ONE};for(int i=0;i<n;){a[++i%2]=a[0].add(a[1]);a[2]=a[2].multiply(a[i%2]);}return a[2];}
This is yet another case where BigInteger
being required due to large numbers. However, I was able to keep the text BigInteger
to a minimum, keeping the size down. I also compared with static imports, and it made the total length longer.
This program works by tracking three numbers in an array. The first two are the previous two Fibonacci numbers. The third is the accumulated value. The loop starts out by calculating the next value and storing it in alternating (0, 1, 0, 1, ...) array indices. This avoids needing to shift values with costly (in terms of source size) assignment operations. Then grab that new value and multiply it into the accumulator.
By avoiding temporary objects and limiting the loop to two assignment operators, I was able to squeeze out quite a few bytes.
Ungolfed:
import java.math.BigInteger;
public class Fibonacci_orial {
public static void main(String[] args) {
// @formatter:off
String[][] testData = new String[][] {
{ "1", "1" },
{ "2", "1" },
{ "3", "2" },
{ "4", "6" },
{ "5", "30" },
{ "6", "240" },
{ "7", "3120" },
{ "8", "65520" },
{ "9", "2227680" },
{ "10", "122522400" },
{ "11", "10904493600" },
{ "12", "1570247078400" },
{ "13", "365867569267200" },
{ "14", "137932073613734400" },
{ "15", "84138564904377984000" },
{ "16", "83044763560621070208000" },
{ "17", "132622487406311849122176000" },
{ "18", "342696507457909818131702784000" },
{ "19", "1432814097681520949608649339904000" },
{ "20", "9692987370815489224102512784450560000" },
{ "100", "3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225261757371666449068625033999573552165524529725467628060170886602001077137613803027158648329335507728698605769992818756765633305318529965186184043999696650407246193257877568825245646129366994079739720698147440310773871269639752334356493678913424390564535389212240038895626811627949132978086070255082668392290037141141291484839596694182152062726390364094447642643912371532491388089634845995941928089653751672688740718152064107169357399466473375804972260594768969952507346694189050233823596316467570584434128052398891223730335019092974935617029638919358286124350711360361279157416837428904150054292406756317837582840596331363581207781793070936765786629772999832857257349696094416616259974304208756997835360702840912518532683324936435856348020736000000000000000000000000" }
};
// @formatter:on
for (String[] data : testData) {
System.out.println("Input: " + data[0]);
System.out.println("Expected: " + data[1]);
System.out.print("Actual: ");
System.out.println(new Fibonacci_orial().f(Integer.parseInt(data[0])));
System.out.println();
}
}
// Begin golf
BigInteger f(int n) {
BigInteger[] a = { BigInteger.ZERO, BigInteger.ONE, BigInteger.ONE };
for (int i = 0; i < n;) {
a[++i % 2] = a[0].add(a[1]);
a[2] = a[2].multiply(a[i % 2]);
}
return a[2];
}
// End golf
}
Program output:
Input: 1
Expected: 1
Actual: 1
Input: 2
Expected: 1
Actual: 1
Input: 3
Expected: 2
Actual: 2
Input: 4
Expected: 6
Actual: 6
Input: 5
Expected: 30
Actual: 30
Input: 6
Expected: 240
Actual: 240
Input: 7
Expected: 3120
Actual: 3120
Input: 8
Expected: 65520
Actual: 65520
Input: 9
Expected: 2227680
Actual: 2227680
Input: 10
Expected: 122522400
Actual: 122522400
Input: 11
Expected: 10904493600
Actual: 10904493600
Input: 12
Expected: 1570247078400
Actual: 1570247078400
Input: 13
Expected: 365867569267200
Actual: 365867569267200
Input: 14
Expected: 137932073613734400
Actual: 137932073613734400
Input: 15
Expected: 84138564904377984000
Actual: 84138564904377984000
Input: 16
Expected: 83044763560621070208000
Actual: 83044763560621070208000
Input: 17
Expected: 132622487406311849122176000
Actual: 132622487406311849122176000
Input: 18
Expected: 342696507457909818131702784000
Actual: 342696507457909818131702784000
Input: 19
Expected: 1432814097681520949608649339904000
Actual: 1432814097681520949608649339904000
Input: 20
Expected: 9692987370815489224102512784450560000
Actual: 9692987370815489224102512784450560000
Input: 100
Expected: 3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225261757371666449068625033999573552165524529725467628060170886602001077137613803027158648329335507728698605769992818756765633305318529965186184043999696650407246193257877568825245646129366994079739720698147440310773871269639752334356493678913424390564535389212240038895626811627949132978086070255082668392290037141141291484839596694182152062726390364094447642643912371532491388089634845995941928089653751672688740718152064107169357399466473375804972260594768969952507346694189050233823596316467570584434128052398891223730335019092974935617029638919358286124350711360361279157416837428904150054292406756317837582840596331363581207781793070936765786629772999832857257349696094416616259974304208756997835360702840912518532683324936435856348020736000000000000000000000000
Actual: 3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225261757371666449068625033999573552165524529725467628060170886602001077137613803027158648329335507728698605769992818756765633305318529965186184043999696650407246193257877568825245646129366994079739720698147440310773871269639752334356493678913424390564535389212240038895626811627949132978086070255082668392290037141141291484839596694182152062726390364094447642643912371532491388089634845995941928089653751672688740718152064107169357399466473375804972260594768969952507346694189050233823596316467570584434128052398891223730335019092974935617029638919358286124350711360361279157416837428904150054292406756317837582840596331363581207781793070936765786629772999832857257349696094416616259974304208756997835360702840912518532683324936435856348020736000000000000000000000000