import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; public class ilo { private static Set<Integer> set = fibonaciNumbersInScope(); private static Set<Integer> results = fibonaciNumbersProducts(set); public static void main(String[] args) throws IOException { // System.out.println(results); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int testsNumber = Integer.parseInt(br.readLine()); for (int i = 0; i < testsNumber; i++) { int input = Integer.parseInt(br.readLine()); if (results.contains(input)) { System.out.println("TAK"); } else { System.out.println("NIE"); } } } private static Set<Integer> fibonaciNumbersInScope() { Set<Integer> set = new TreeSet<>(); int before = 1; int tmp = 1; long MAX_PRODUCT = 1_000_000_000; long MAX = Math.round(Math.sqrt(MAX_PRODUCT)) + 1; while (tmp <= MAX) { set.add(tmp); int t = before + tmp; before = tmp; tmp = t; } return set; } private static Set<Integer> fibonaciNumbersProducts(Set<Integer> set) { Set<Integer> results = new HashSet<>(); for (Iterator<Integer> first = set.iterator(); first.hasNext();) { Integer a = first.next(); for (Integer b : set) { results.add(a * b); } first.remove(); } return results; } }
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 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; public class ilo { private static Set<Integer> set = fibonaciNumbersInScope(); private static Set<Integer> results = fibonaciNumbersProducts(set); public static void main(String[] args) throws IOException { // System.out.println(results); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int testsNumber = Integer.parseInt(br.readLine()); for (int i = 0; i < testsNumber; i++) { int input = Integer.parseInt(br.readLine()); if (results.contains(input)) { System.out.println("TAK"); } else { System.out.println("NIE"); } } } private static Set<Integer> fibonaciNumbersInScope() { Set<Integer> set = new TreeSet<>(); int before = 1; int tmp = 1; long MAX_PRODUCT = 1_000_000_000; long MAX = Math.round(Math.sqrt(MAX_PRODUCT)) + 1; while (tmp <= MAX) { set.add(tmp); int t = before + tmp; before = tmp; tmp = t; } return set; } private static Set<Integer> fibonaciNumbersProducts(Set<Integer> set) { Set<Integer> results = new HashSet<>(); for (Iterator<Integer> first = set.iterator(); first.hasNext();) { Integer a = first.next(); for (Integer b : set) { results.add(a * b); } first.remove(); } return results; } } |