import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class ilo { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); long time = System.currentTimeMillis(); int[] values = calculateFibNumbers(); final int n = Integer.parseInt(reader.readLine()); for(int i = 0;i < n;i++) { calculateAnswer(reader, values); } System.err.println("time = " + (System.currentTimeMillis() - time)); } private static int[] calculateFibNumbers() { final int max = 1000 * 1000 * 1000; long previousValue = 0; long value = 1; List<Integer> values = new ArrayList<Integer>(45); values.add(0); while(true) { long temp = value; value += previousValue; if(value > max) { break; } previousValue = temp; values.add((int)value); } int[] valuesArray = new int[values.size()]; int i = 0; for(Integer val : values) { valuesArray[i++] = val; } return valuesArray; } private static void calculateAnswer(BufferedReader reader, int[] values) throws IOException { final int value = Integer.parseInt(reader.readLine()); for(int i = 0;i < values.length;i++) { for(int j = 0;j < values.length;j++) { if(values[i] * values[j] == value) { System.out.println("TAK"); return; } } } System.out.println("NIE"); } }
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 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class ilo { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); long time = System.currentTimeMillis(); int[] values = calculateFibNumbers(); final int n = Integer.parseInt(reader.readLine()); for(int i = 0;i < n;i++) { calculateAnswer(reader, values); } System.err.println("time = " + (System.currentTimeMillis() - time)); } private static int[] calculateFibNumbers() { final int max = 1000 * 1000 * 1000; long previousValue = 0; long value = 1; List<Integer> values = new ArrayList<Integer>(45); values.add(0); while(true) { long temp = value; value += previousValue; if(value > max) { break; } previousValue = temp; values.add((int)value); } int[] valuesArray = new int[values.size()]; int i = 0; for(Integer val : values) { valuesArray[i++] = val; } return valuesArray; } private static void calculateAnswer(BufferedReader reader, int[] values) throws IOException { final int value = Integer.parseInt(reader.readLine()); for(int i = 0;i < values.length;i++) { for(int j = 0;j < values.length;j++) { if(values[i] * values[j] == value) { System.out.println("TAK"); return; } } } System.out.println("NIE"); } } |