Advertisement
chillurbrain

5. Дипломы

May 25th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import java.io.*;
  2. import java.math.BigInteger;
  3. import java.util.*;
  4.  
  5. public class Main {
  6.     public static BigInteger max(BigInteger x, BigInteger y) {
  7.         return x.compareTo(y) > 0 ? x : y;
  8.     }
  9.  
  10.     public static void main(String args[]) {
  11.         try (PrintWriter out = new PrintWriter(System.out);) {
  12.             Scanner in = new Scanner(System.in);
  13.  
  14.             BigInteger w = in.nextBigInteger();
  15.             BigInteger h = in.nextBigInteger();
  16.             BigInteger n = in.nextBigInteger();
  17.             BigInteger two = new BigInteger("2");
  18.  
  19.             BigInteger l = BigInteger.ONE;
  20.             BigInteger r = n.multiply(max(w, h));
  21.             BigInteger x = w.multiply(h).multiply(n);
  22.  
  23.             while (l.compareTo(r) < 0) {
  24.                 BigInteger m = l.add(r).divide(two);
  25.  
  26.                 BigInteger width = m.divide(w);
  27.                 BigInteger height = m.divide(h);
  28.                 BigInteger num = width.multiply(height);
  29.  
  30.                 if (m.multiply(m).compareTo(x) < 0 || num.compareTo(n) < 0)
  31.                     l = m.add(BigInteger.ONE);
  32.                 else
  33.                     r = m;
  34.             }
  35.  
  36.             out.print(r.toString());
  37.         } catch(Exception e) {
  38.             System.out.println("Exception: " + e);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement