//import java.io.BufferedReader; //import java.io.FileReader; import java.util.ArrayList; import java.util.Scanner; public class ilo { private ArrayList<Integer> fiboNums = new ArrayList<>(); private ilo() { fiboNums.add(1); fiboNums.add(1); } private void checkValues(int[] values) { for (int value : values) { checkValue(value); } } private void checkValue(int value) { assertMaxKnownFibo(value); for (int i = 1; i < fiboNums.size(); i++) { int fiboNum = fiboNums.get(i); if (value % fiboNum == 0 && fiboNums.contains(value / fiboNum)) { System.out.println("TAK"); return; } } System.out.println("NIE"); } private void assertMaxKnownFibo(int value) { int lastKnownFibo = fiboNums.get(fiboNums.size() - 1); while (lastKnownFibo < value) { lastKnownFibo = addFibo(); } } private int addFibo() { int lastFibo = fiboNums.get(fiboNums.size() - 1); int prevFibo = fiboNums.get(fiboNums.size() - 2); int newFibo = prevFibo + lastFibo; fiboNums.add(newFibo); return newFibo; } public static void main(String[] ignore) throws Exception { //System.out.println("Tutaj!"); //System.out.println(params.length); /* System.out.println(params[0]); int[] values; try (BufferedReader reader = new BufferedReader(new FileReader(params[0]))) { String line = reader.readLine(); values = new int[Integer.parseInt(line, 10)]; int i = 0; while ((line = reader.readLine()) != null) { values[i++] = Integer.parseInt(line, 10); } } */ Scanner input = new Scanner(System.in); int len = Integer.parseInt(input.nextLine(), 10); int[] values = new int[len]; for (int i = 0; i < len; i++) { values[i] = Integer.parseInt(input.nextLine(), 10); } /* int[] values = new int[params.length - 1]; for (int i = 1; i < params.length; i++) { System.out.println("|" + params[i] + "|"); values[i - 1] = Integer.parseInt(params[i], 10); } */ new ilo().checkValues(values); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | //import java.io.BufferedReader; //import java.io.FileReader; import java.util.ArrayList; import java.util.Scanner; public class ilo { private ArrayList<Integer> fiboNums = new ArrayList<>(); private ilo() { fiboNums.add(1); fiboNums.add(1); } private void checkValues(int[] values) { for (int value : values) { checkValue(value); } } private void checkValue(int value) { assertMaxKnownFibo(value); for (int i = 1; i < fiboNums.size(); i++) { int fiboNum = fiboNums.get(i); if (value % fiboNum == 0 && fiboNums.contains(value / fiboNum)) { System.out.println("TAK"); return; } } System.out.println("NIE"); } private void assertMaxKnownFibo(int value) { int lastKnownFibo = fiboNums.get(fiboNums.size() - 1); while (lastKnownFibo < value) { lastKnownFibo = addFibo(); } } private int addFibo() { int lastFibo = fiboNums.get(fiboNums.size() - 1); int prevFibo = fiboNums.get(fiboNums.size() - 2); int newFibo = prevFibo + lastFibo; fiboNums.add(newFibo); return newFibo; } public static void main(String[] ignore) throws Exception { //System.out.println("Tutaj!"); //System.out.println(params.length); /* System.out.println(params[0]); int[] values; try (BufferedReader reader = new BufferedReader(new FileReader(params[0]))) { String line = reader.readLine(); values = new int[Integer.parseInt(line, 10)]; int i = 0; while ((line = reader.readLine()) != null) { values[i++] = Integer.parseInt(line, 10); } } */ Scanner input = new Scanner(System.in); int len = Integer.parseInt(input.nextLine(), 10); int[] values = new int[len]; for (int i = 0; i < len; i++) { values[i] = Integer.parseInt(input.nextLine(), 10); } /* int[] values = new int[params.length - 1]; for (int i = 1; i < params.length; i++) { System.out.println("|" + params[i] + "|"); values[i - 1] = Integer.parseInt(params[i], 10); } */ new ilo().checkValues(values); } } |