fork download
  1.  
  2. import java.io.BufferedInputStream;
  3. import java.io.IOException;
  4.  
  5. public class Main {
  6.  
  7. static class Entrada {
  8. private final BufferedInputStream in =
  9.  
  10. int leerEntero() throws IOException {
  11. int c;
  12.  
  13. do {
  14. c = in.read();
  15. } while (c <= 32 && c != -1);
  16.  
  17. int num = 0;
  18.  
  19. while (c > 32) {
  20. num = num * 10 + c - '0';
  21. c = in.read();
  22. }
  23.  
  24. return num;
  25. }
  26. }
  27.  
  28. static int calcularMCD(int a, int b) {
  29. while (b != 0) {
  30. int resto = a % b;
  31. a = b;
  32. b = resto;
  33. }
  34.  
  35. return Math.abs(a);
  36. }
  37.  
  38. static int calcularOp(int[] a) {
  39. int operaciones = 0;
  40. int n = a.length;
  41.  
  42. for (int i = 0; i < n - 1; i++) {
  43. if (a[i] % 2 != 0) {
  44. if (a[i + 1] % 2 != 0) {
  45. operaciones++;
  46. i++;
  47. } else {
  48. operaciones += 2;
  49. }
  50. }
  51. }
  52.  
  53. return operaciones;
  54. }
  55.  
  56. public static void main(String[] args) throws Exception {
  57. Entrada entrada = new Entrada();
  58.  
  59. int n = entrada.leerEntero();
  60. int[] a = new int[n];
  61. int mcd = 0;
  62.  
  63. for (int i = 0; i < n; i++) {
  64. a[i] = entrada.leerEntero();
  65. mcd = calcularMCD(mcd, a[i]);
  66. }
  67.  
  68. if (mcd > 1) {
  69. System.out.println("YES");
  70. System.out.println(0);
  71. } else {
  72. System.out.println("YES");
  73. System.out.println(calcularOp(a));
  74. }
  75. }
  76. }
  77.  
Success #stdin #stdout 0.07s 32212KB
stdin
Standard input is empty
stdout
YES
0