import java.io.BufferedReader; import java.io.InputStreamReader; public class ilo { public static void main(String[] args) throws Exception { long[] F = new long[100]; int N = 2; F[0] = 0; F[1] = 1; for (; F[N-1] <= 1000 * 1000 * 1000; N++) { F[N] = F[N-1] + F[N-2]; } System.err.println(N); System.err.println(F[N-1]); System.err.println(F[N-1]*F[N-1]); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; int T; line = br.readLine(); T = Integer.valueOf(line.trim()); for (int i = 0; i < T; i++) { long X; line = br.readLine(); X = Long.valueOf(line.trim()); boolean found = false; for (int j = 0; j < N && !found; j++) { for (int k = 0; k < N; k++) { if ( F[j] * F[k] == X ) { found = true; break; } } } System.out.println( found ? "TAK" : "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 | import java.io.BufferedReader; import java.io.InputStreamReader; public class ilo { public static void main(String[] args) throws Exception { long[] F = new long[100]; int N = 2; F[0] = 0; F[1] = 1; for (; F[N-1] <= 1000 * 1000 * 1000; N++) { F[N] = F[N-1] + F[N-2]; } System.err.println(N); System.err.println(F[N-1]); System.err.println(F[N-1]*F[N-1]); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; int T; line = br.readLine(); T = Integer.valueOf(line.trim()); for (int i = 0; i < T; i++) { long X; line = br.readLine(); X = Long.valueOf(line.trim()); boolean found = false; for (int j = 0; j < N && !found; j++) { for (int k = 0; k < N; k++) { if ( F[j] * F[k] == X ) { found = true; break; } } } System.out.println( found ? "TAK" : "NIE" ); } } } |