Tuesday, November 8, 2016

UVa 11715

#include<bits/stdc++.h>

using namespace std;

int main() {
  int T;
  int c = 0;
  double u, v, t, a, s;

  while (cin >> T) {
    if (T == 0)
      break;

    c++;

    cout << "Case " << c << ": ";

    switch (T) {
      case 1:
        cin >> u >> v >> t;
        a = (v - u) / t;
        s = u * t + 0.5 * a * t * t;
        cout << setprecision(3) << fixed << s << " " << a << endl;
        break;
      case 2:
        cin >> u >> v >> a;
        t = (v - u) / a;
        s = u * t + 0.5 * a * t * t;
        cout << setprecision(3) << fixed  << s << " " << t << endl;
        break;
      case 3:
        cin >> u >> a >> s;
        t = (-u + sqrt(u * u + 2 * a * s)) / a;
        v = a * t + u;
        cout << setprecision(3) << fixed  << v << " " << t << endl;
        break;
      case 4:
        cin >> v >> a >> s;
        t = (-v + sqrt(v * v - 2 * a * s)) / -a;
        u = v - a * t;
        cout << setprecision(3) << fixed  << u << " " << t << endl;
        break;
    }
  }

  return 0;
}

Wednesday, November 2, 2016

UVa 1230

import java.util.Scanner;
import java.math.BigInteger;

class Main { 

  public static void main(String args[])
   {

    Scanner sc = new Scanner(System.in);
    int c = sc.nextInt();

    while (c-- > 0) {

         BigInteger x = BigInteger.valueOf(sc.nextInt()); 
         BigInteger y = BigInteger.valueOf(sc.nextInt()); 
         BigInteger n = BigInteger.valueOf(sc.nextInt()); 
         System.out.println(x.modPow(y, n)); 
   }
  } 
}

UVa 343

import java.io.*;
import java.util.*;
import java.math.*;

class Main{

  void sol()
  {
   Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

    while(in.hasNext())
    {
      String a=in.next();
      String b=in.next();
      BigInteger b1,b2;
      boolean f=false;

       for(int i=2; i<=36; i++)
       {
        try{
         b1=new BigInteger(a,i);
         }

         catch(Exception e)
         {
          continue;
          }

          for(int j=2; j<=36; j++)
          {
           try{
            b2= new BigInteger(b,j);
           }
           catch(Exception e)
           {
            continue;
           }

           if(b1.compareTo(b2)==0){
            f=true;
            System.out.println(a + " (base " + i + ") = " + b + " (base " + j + ")");
            break;

           }

          }

          if(f) break;
        }
         if(!f) System.out.println(a + " is not equal to " + b + " in any base 2..36");


     }


   }


   public static void main(String args[])
   {
    Main uva343 = new Main();
    uva343.sol();
   }


 }