Created
November 5, 2015 23:25
-
-
Save ayakimchuk322/be19a942c936388db9e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigInteger; | |
import java.util.*; | |
public class Pentanacci2 { | |
public static long countOddPentaFib(long n) { | |
// your code | |
BigInteger temp = new BigInteger("0"); | |
long count = 0; | |
List<BigInteger> pentafib = new ArrayList<BigInteger>(); | |
pentafib.add(BigInteger.valueOf(0)); | |
pentafib.add(BigInteger.valueOf(1)); | |
pentafib.add(BigInteger.valueOf(1)); | |
pentafib.add(BigInteger.valueOf(2)); | |
pentafib.add(BigInteger.valueOf(4)); | |
switch ((int)n){ | |
case 0: return 0; | |
case 1: | |
case 2: | |
case 3: | |
case 4: return 1; | |
default: | |
try { | |
for (int i = 0; i < n - 4; i++){ //should always pay attention to the fact arrays start with 0 index | |
for (int j = 0; j < 5; j++){ | |
try{ | |
temp = temp.add(pentafib.get(pentafib.size() - 1 - j)); | |
} catch (IndexOutOfBoundsException ex){ | |
} | |
} | |
pentafib.add(temp); | |
temp = BigInteger.ZERO; | |
} | |
} finally { | |
} | |
System.out.println(pentafib); | |
for (BigInteger t : pentafib) { | |
try { | |
if ((t.remainder(BigInteger.valueOf(2))) != BigInteger.ZERO){ | |
count++; | |
} | |
} finally{ | |
} | |
} | |
return --count; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment