import java.util.Scanner; public class ilo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); //generate fib tab int[] tabFib = new int[45]; int id = 2; //init 0 i 1 tabFib[0]=0; //a tabFib[1]=1; //b int a = 0; int b = 1; int tmp = 0; //System.out.println(a+", "); //System.out.println(b+", "); while (a+b<1000000000) { tmp = b; b = b + a; a = tmp; // System.out.println(b+", "); tabFib[id]=b; id++; } for(int i=0; i<count; i++) { int fib = sc.nextInt(); checkFib(fib,tabFib); // checkFib((int)Math.pow(10.0,9.0)); } } private static void checkFib(int numberToCheck, int[] tabFib) { // System.out.println(numberToCheck); int ilo1 = 0; int ilo2 = 0; for(int i=1;i<tabFib.length;i++) { //bez 0 if(numberToCheck % tabFib[i]==0) { //dzielenie modulo ilo1 = tabFib[i]; for(int j=1;j<tabFib.length;j++) { //bez 0 if(numberToCheck % tabFib[j]==0) { //dzielenie modulo ilo2 = tabFib[j]; if(numberToCheck == ilo1*ilo2) { System.out.println("TAK"); return; } } } } } System.out.println("NIE"); return; } }
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 | import java.util.Scanner; public class ilo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); //generate fib tab int[] tabFib = new int[45]; int id = 2; //init 0 i 1 tabFib[0]=0; //a tabFib[1]=1; //b int a = 0; int b = 1; int tmp = 0; //System.out.println(a+", "); //System.out.println(b+", "); while (a+b<1000000000) { tmp = b; b = b + a; a = tmp; // System.out.println(b+", "); tabFib[id]=b; id++; } for(int i=0; i<count; i++) { int fib = sc.nextInt(); checkFib(fib,tabFib); // checkFib((int)Math.pow(10.0,9.0)); } } private static void checkFib(int numberToCheck, int[] tabFib) { // System.out.println(numberToCheck); int ilo1 = 0; int ilo2 = 0; for(int i=1;i<tabFib.length;i++) { //bez 0 if(numberToCheck % tabFib[i]==0) { //dzielenie modulo ilo1 = tabFib[i]; for(int j=1;j<tabFib.length;j++) { //bez 0 if(numberToCheck % tabFib[j]==0) { //dzielenie modulo ilo2 = tabFib[j]; if(numberToCheck == ilo1*ilo2) { System.out.println("TAK"); return; } } } } } System.out.println("NIE"); return; } } |