Esempio n. 1
0
 public static void main(String[] args) throws Exception {
   // System.setIn(new
   // FileInputStream("E:/Shreyans/Documents/Code/CODE/SPOJ/Stdin_File_Read.txt"));
   InputReader in = new InputReader(System.in);
   OutputWriter out = new OutputWriter(System.out);
   int n = in.readInt();
   int[] a = new int[n];
   for (int i = 0; i < n; i++) {
     a[i] = in.readInt();
   }
   HashSet<Integer> hs = new HashSet<Integer>();
   for (int i = 0; i < n; i++) {
     while (a[i] % 2 == 0) {
       a[i] /= 2;
     }
     while (a[i] % 3 == 0) {
       a[i] /= 3;
     }
     hs.add(a[i]);
     if (hs.size() > 1) {
       out.printLine("No");
       return;
     }
   }
   out.printLine("Yes");
 }
 public static void main(String[] args) throws Exception {
   // System.setIn(new
   // FileInputStream("E:/Shreyans/Documents/Code/CODE/SPOJ/Stdin_File_Read.txt"));
   InputReader in = new InputReader(System.in);
   OutputWriter out = new OutputWriter(System.out);
   int t = in.readInt();
   NXT:
   while (t-- > 0) {
     int n = in.readInt();
     long[] a = new long[n];
     for (int i = 0; i < n; i++) {
       a[i] = (long) in.readDouble();
     }
     long ans = 1;
     for (int j = 0; j < n; j++) {
       ans -= a[j];
       ans *= 2;
       if (ans < 0) {
         out.printLine("No");
         continue NXT;
       }
     }
     if (ans != 0) {
       out.printLine("No");
     } else {
       out.printLine("Yes");
     }
   }
 }
Esempio n. 3
0
 public static void main(String[] args) {
   InputReader ir = new InputReader(System.in);
   OutputWriter ow = new OutputWriter(System.out);
   int tests = ir.readInt();
   for (int i = 0; i < tests; i++) {
     int num = ir.readInt();
     if ((num & 1) == 0) ow.printLine("ALICE");
     else ow.printLine("BOB");
   }
   ow.close();
 }
 public static void main(String[] args) throws Exception {
   InputReader in = new InputReader(System.in);
   OutputWriter out = new OutputWriter(System.out);
   int n = in.readInt();
   long m = in.readLong();
   long[] b = new long[n];
   long mf = 0;
   for (int i = 0; i < n; i++) {
     b[i] = in.readLong();
   }
   long ans = 0;
   long cntm = 0;
   for (int j = 0; j < n; j++) {
     ans += ((b[j] * (b[j] * (b[j] + 1) / 2)) % m);
     if (b[j] <= m) {
       ans += FACT(b[j], m);
       // ans=ans.mod(m);
     } else {
       if (cntm == 0) {
         mf = FACT(m, m);
         cntm++;
       }
       ans += mf;
       // ans=ans.mod(m);
     }
     // System.out.println(ans);
     // ans=ans.mod(new BigInteger(Integer.toString(m)));
   }
   out.printLine(ans);
   {
     out.close();
   }
 }
Esempio n. 5
0
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      String X;
      PriorityQueue<Integer> pq = new PriorityQueue<>();
      Stack<Integer> stack = new Stack<>();

      while ((X = in.next()) != null) {
        int x = Integer.valueOf(X);
        pq.add(x);
        int sz = pq.size();
        int median = 0;

        if (sz == 1) {
          median = pq.peek();
        } else {
          for (int i = 0; i <= sz / 2; i++) {
            stack.add(pq.poll());
            if ((i == (sz / 2) - 1 && sz % 2 == 0) || i == (sz / 2)) {
              median += stack.peek();
            }
          }
          if (sz % 2 == 0) median /= 2;
        }

        while (!stack.isEmpty()) pq.add(stack.pop());
        out.printLine(median);
      }
    }
  public static void main(String[] args) throws Exception {
    InputReader in = new InputReader(System.in);
    OutputWriter out = new OutputWriter(System.out);
    int t = in.readInt();
    int[] a = new int[400000000];
    for (int j = 1; j <= 400000000; j++) {
      int ans2 = 0;
      int j1 = j;
      while (j1 > 0) {
        int x = j1 % 10;
        if (x % 2 == 0) {
          ans2 += (2 * x);
        } else {
          ans2 += x;
        }
        j1 = j1 / 10;
      }
      a[j - 1] = ans2 % 10;
    }
    for (int i = 0; i < t; i++) {
      int a1 = in.readInt();
      int b1 = in.readInt();
      int ans = 0;
      for (int j = a1; j <= b1; j++) {

        ans += a[j - 1];
      }
      out.printLine(ans);
    }

    {
      out.close();
    }
  }
 public static void main(String[] args) throws Exception {
   InputReader in = new InputReader(System.in);
   OutputWriter out = new OutputWriter(System.out);
   int t = in.readInt();
   for (int i = 0; i < t; i++) {
     int a = in.readInt();
     if (a % 2 == 0) {
       out.printLine(a);
     } else {
       out.printLine(a - 1);
     }
   }
   {
     out.close();
   }
 }
Esempio n. 8
0
 public void solve(int testNumber, InputReader in, OutputWriter out) {
   long money = in.readLong();
   long fee = in.readLong();
   int count = in.readInt();
   long[] price = new long[count];
   long[] stale = new long[count];
   IOUtils.readLongArrays(in, price, stale);
   long currentDeliveryCost = fee;
   long lastStale = -1;
   long[] antiStale = stale.clone();
   for (int i = 0; i < count; i++) antiStale[i] = -antiStale[i];
   Integer[] order = ListUtils.order(Array.wrap(price), Array.wrap(antiStale));
   long answer = 0;
   for (int i : order) {
     if (lastStale >= stale[i]) continue;
     long p1 = currentDeliveryCost;
     long p2 = price[i];
     long q = stale[i] - lastStale;
     long c = lastStale + 1;
     if (p1 / p2 >= c) {
       if (money / q >= price[i]) {
         long alpha1 = money / (currentDeliveryCost + q * price[i]);
         long beta1 = q * alpha1;
         if (alpha1 * p1 + beta1 * p2 > money) throw new RuntimeException();
         if (beta1 > q * alpha1) throw new RuntimeException();
         answer = Math.max(answer, c * alpha1 + beta1);
         long alpha2 = alpha1 + 1;
         if (alpha2 * currentDeliveryCost <= money) {
           long remainingMoney = money - alpha2 * p1;
           long beta2 = remainingMoney / p2;
           if (alpha2 * p1 + beta2 * p2 > money) throw new RuntimeException();
           if (beta2 > q * alpha2) throw new RuntimeException();
           answer = Math.max(answer, c * alpha2 + beta2);
         }
       } else {
         long alpha = 1;
         long beta = (money - currentDeliveryCost) / p2;
         if (alpha * p1 + beta * p2 > money) throw new RuntimeException();
         if (beta > q * alpha) throw new RuntimeException();
         answer = Math.max(answer, c * alpha + beta);
       }
     } else {
       long alpha = money / p1;
       long remainingMoney = money - alpha * p1;
       long beta = remainingMoney / p2;
       if (remainingMoney / q >= alpha) beta = Math.min(beta, alpha * q);
       if (alpha * p1 + beta * p2 > money) throw new RuntimeException();
       if (beta > q * alpha) throw new RuntimeException();
       answer = Math.max(answer, c * alpha + beta);
     }
     if (money / price[i] >= stale[i] - lastStale) {
       currentDeliveryCost += (stale[i] - lastStale) * price[i];
       lastStale = stale[i];
     } else break;
     if (currentDeliveryCost > money) break;
   }
   out.printLine("Case #" + testNumber + ":", answer);
 }
  public static void main(String[] args) throws Exception {
    // System.setIn(new
    // FileInputStream("E:/Shreyans/Documents/Code/CODE/SPOJ/Stdin_File_Read.txt"));
    InputReader in = new InputReader(System.in);
    OutputWriter out = new OutputWriter(System.out);
    int n = in.readInt(), k = in.readInt(), d = in.readInt();
    long[] dp1 = new long[n + 1], dp2 = new long[n + 1];
    dp1[0] = dp2[0] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = i - 1; j >= i - k && j >= 0; j--) {
        dp1[i] = (dp1[i] % MOD + dp1[j] % MOD) % MOD;
      }

      for (int j = i - 1; j >= i - d + 1 && j >= 0; j--) {
        dp2[i] = (dp2[i] % MOD + dp2[j] % MOD) % MOD;
      }
    }
    long ans = ((dp1[n] % MOD - dp2[n] % MOD) + MOD) % MOD;
    out.printLine(ans);
  }
Esempio n. 10
0
 public static void main(String[] args) throws Exception {
   // System.setIn(new
   // FileInputStream("E:/Shreyans/Documents/Code/CODE/SPOJ/Stdin_File_Read.txt"));
   InputReader in = new InputReader(System.in);
   OutputWriter out = new OutputWriter(System.out);
   int n = in.readInt(), k = in.readInt(), seg = n / k;
   int[] a = new int[seg], b = new int[seg], cases = new int[seg];
   for (int i = 0; i < seg; i++) {
     a[i] = in.readInt();
   }
   for (int i = 0; i < seg; i++) {
     b[i] = in.readInt();
   }
   int[] ten = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000},
       nine = {0, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999};
   for (int i = 0; i < (n / k); i++) {
     cases[i] = 0;
     cases[i] = ten[k] / a[i];
     if (ten[k] % a[i] == 0) {
       cases[i]--;
     }
     cases[i] = cases[i] % MOD;
     if (b[i] == 0) {
       cases[i] = cases[i] - ((ten[k - 1] - 1) / a[i]);
       continue;
     }
     int lw = (b[i] - 1) * ten[k - 1] + nine[k - 1];
     int up = b[i] * ten[k - 1] + nine[k - 1];
     int lw_cases = lw / a[i];
     int up_cases = up / a[i];
     cases[i] = cases[i] - (up_cases - lw_cases);
     cases[i] = (cases[i] + 1) % MOD;
   }
   long prod = 1;
   for (int i = 0; i < (n / k); i++) {
     prod = (prod * cases[i]) % MOD;
   }
   out.printLine(prod);
 }
  public static void main(String[] args) throws Exception {
    InputReader in = new InputReader(System.in);
    OutputWriter out = new OutputWriter(System.out);
    int t = in.readInt();
    for (int i = 0; i < t; i++) {
      String a = in.readString();
      int kmax = 0, k = 0, is = 0, ie = 0, max1 = 0, max2 = 0;
      int rmax = 0, r = 0;
      for (int j = 0; j < a.length(); j++) {
        if (a.charAt(j) == 'K') {
          if (r > rmax) {
            rmax = r;
          }
          if (k == 0) {
            is = j;
          } else {
            ie = j;
          }
          k++;
        } else {
          r++;
          if (k > kmax) {
            kmax = k;
          }
          if (ie - is > (max2 - max1)) {
            max1 = is;
            max2 = ie;
          }
          k = 0;
        }
      }
      if (r > rmax) {
        rmax = r;
      }
      if (k > kmax) {
        kmax = k;
      }
      if (ie - is > (max2 - max1)) {
        max1 = is;
        max2 = ie;
      }
      if (rmax > kmax) {
        out.printLine(rmax);
      } else {
        int ans = kmax;
        for (int j = max1 - 1; j >= 0; j--) {
          if (a.charAt(j) == 'R') {
            ans++;
          }
        }
        for (int j = max2 + 1; j < a.length(); j++) {
          if (a.charAt(j) == 'R') {
            ans++;
          }
        }
        out.printLine(ans);
      }
    }

    {
      out.close();
    }
  }