1011. Conductors
Time limit: 2.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Background
Everyone making translations from English to Russian knows an English phrase "Naked conductor runs along the bus". It has two very different meanings.
Problem
Every bus in the Ekaterinburg city has a special man (or woman) called conductor. When you ride the bus, you have to give money to the conductor. We know that there are more than
P% conductors and less than
Q% conductors of all citizens of Ekaterinburg. Your task is to determine a minimal possible number of Ekaterinburg citizens. By percentage, we know that there are more than P% conductors and less than Q% conductors of all Russian citizens in this city
Input
Two numbers
P,
Q such that 0.01 ≤
P,
Q ≤ 99.99. Numbers are given with 2 digits precision. These numbers are separated by some spaces or "end of line" symbols.
Output
The minimal number of Ekaterinburg citizens.
Sample
input | output |
---|---|
13 14.1 | 15 |
Notes
If there are 15 citizens and 2 conductors among them in Ekaterinburg, then there are 13 1/3 % conductors of all citizens.
Problem Source: USU Championship 1997
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
new Task().solve();
}
}
class Task {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
boolean jduge(long p , long q , long n){
for(long k = 1 ; k < n ; k++){
if(p * n < k * 10000 && k * 10000 < q * n){
return true ;
}
}
return false ;
}
long gao(long p , long q) {
long n = 0 ;
while(true){
if(jduge(p, q, n)){
return n ;
}
n++ ;
}
}
void table() {
TreeSet<Long> a = new TreeSet<Long>() ;
for(long i = 1 ; i <= 9999 ; i++){
for(long j = i+1 ; j <= 9999 ; j++){
long n = gao(i, j) ;
a.add(n) ;
}
}
try {
out = new PrintWriter(new File("a.txt")) ;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.println(a) ;
out.print(a.size());
out.flush();
}
int[] select = new int[]{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 241, 242, 243, 244, 245, 246, 247, 248, 249, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 291, 292, 293, 294, 295, 296, 297, 298, 299, 301, 302, 304, 305, 306, 309, 310, 312, 313, 314, 315, 316, 317, 318, 319, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 345, 346, 347, 348, 349, 352, 354, 355, 356, 358, 359, 361, 362, 365, 367, 368, 371, 372, 374, 376, 380, 384, 385, 386, 388, 389, 390, 395, 397, 399, 401, 402, 403, 404, 406, 407, 408, 409, 411, 412, 413, 414, 416, 417, 418, 419, 421, 422, 423, 424, 428, 432, 435, 436, 437, 441, 443, 448, 455, 457, 458, 459, 464, 466, 470, 477, 478, 483, 501, 502, 503, 504, 506, 507, 509, 511, 512, 513, 517, 519, 527, 529, 530, 532, 535, 556, 557, 558, 561, 565, 589, 590, 593, 594, 596, 626, 627, 628, 629, 631, 632, 633, 634, 635, 636, 637, 638, 639, 641, 667, 668, 669, 671, 674, 715, 716, 718, 719, 722, 770, 772, 773, 776, 834, 835, 837, 838, 910, 911, 914, 1001, 1002, 1003, 1004, 1007, 1009, 1112, 1115, 1251, 1253, 1255, 1257, 1429, 1667, 2001, 2002, 2003, 2004, 2501, 2503, 3334, 5001} ;
long calc(long p , long q) {
long n = 0 ;
for(int s : select){
if(jduge(p, q, s)){
return s ;
}
n++ ;
}
return -1 ;
}
void solve() {
// table();
long p = (long)(in.nextDouble() * 100 + 0.5) ;
long q = (long)(in.nextDouble() * 100 + 0.5) ;
out.println(calc(p, q));
out.flush() ;
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = new StringTokenizer("");
}
private void eat(String s) {
tokenizer = new StringTokenizer(s);
}
public String nextLine() {
try {
return reader.readLine();
} catch (Exception e) {
return null;
}
}
public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String s = nextLine();
if (s == null)
return false;
eat(s);
}
return true;
}
public String next() {
hasNext();
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public int[] nextInts(int n) {
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = nextInt();
}
return nums;
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
}