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 |
import java.util.ArrayList; import java.util.Scanner; /** * UVA948 */ public class UVA948 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); for (int j = 0; j < count; j++) { int n = sc.nextInt(); int N = n; ArrayList<Integer> intList = new ArrayList<Integer>(); intList.add(1); if (n >= 1) { intList.add(2); int temp = 0; while (temp <= n) { temp = intList.get(intList.size() - 2) + intList.get(intList.size() - 1); intList.add(temp); } } String fib = ""; for (int i = intList.size() - 2; i >= 0; i--) { int get = intList.get(i); if (n >= get) { n -= get; fib += "1"; } else fib += "0"; } if (N == 1) fib = "1"; System.out.printf("%d = %s (fib)\r\n", N, fib); } sc.close(); } } |