@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the RSA key sent by the remote host is [...]. Please contact your system administrator. Add correct host key in */.ssh/known_hosts to get rid of this message. Offending RSA key in*d/.ssh/known_hosts:86 RSA host key for [...] has changed and you have requested strict checking. Host key verification failed.
math: # Default (false) will load mathjax / katex script on demand. # That is it only render those page which has `mathjax: true` in front-matter. # If you set it to true, it will load mathjax / katex script EVERY PAGE. every_page: false
publicstaticvoidmain(String[] args){ Scanner input = new Scanner(System.in); w15p6(input); }
publicstaticvoidw15p6(Scanner input){ // Map用于存放输入数据中不同的数及其出现的次数 Map<Integer, Integer> map = new HashMap<>();
// 输入数据的过程 int n = input.nextInt(); for (int i = 0; i < n * n; i++) { int in = input.nextInt(); if (map.containsKey(in)) map.put(in, map.get(in) + 1); else map.put(in, 1); }
// result数组用于存放计算过程中的最大公因数 // 由于result数组初始化为0,恰好 int[] result = newint[n]; for (int i = 0; i < n; i++) { // 从所有公因数中找到最大的作为当前最大公因数,放入result数组中 result[i] = getKey(map); // 存放后,将这个数移除到所有出现的公因数中,表示移除这个数与自身进行的最大公因数计算结果 // 其他数与这个数的最大公因数计算结果在其他数被找到时计算并移除 // 仅移除1个,如果这个数出现次数为0,则将key从Map中清除 map.put(result[i], map.get(result[i]) - 1); if (map.get(result[i]) == 0) { map.remove(result[i]); } for (int j = 0; j < i; j++) { // 遍历所有此前已找到的数 // 计算此前已找到的数与当前找到的数的公因数 int x = gcd(result[i], result[j]); // 将这个公因数从Map中移除两次,因为一对数之间有两次最大公因数的计算 if (map.containsKey(x)) { map.put(x, map.get(x) - 1); if (map.get(x) == 0) map.remove(x); } if (map.containsKey(x)) { map.put(x, map.get(x) - 1); if (map.get(x) == 0) map.remove(x); } } } // 倒序输出 for (int i = n - 1; i >= 0 ; i--) { System.out.print(result[i]); if (i != 0) System.out.print(" "); }