auricoso2000
BAN USERGahh. 14040 / (9 * 60) = 14040 / 540 = 26.
- auricoso2000 March 30, 2015Total number of seconds: 14400.
Minus 6 minutes = 14400 - (6 * 60) = 14040.
14040 remaining seconds. How many 9-minute calls fit in this time?
== 14040 / (9 * 6) = 14040 / 540 = 26.
Answer: 26 calls.
Ha ha?
- auricoso2000 February 08, 2015A brute-force method in java. Can be improved with memoization et al, and most likely has overflow errors.
//
// Assumes that p and q are both > 1, so n must be >= 4.
//
public static boolean nCanBePToTheQ(long n) {
if (n <= 4) {
return true;
}
for (int p = 2; p < n; p++) {
// trivial reject if n isn't a multiple of p
if ((n % p) != 0) {
continue;
}
for (int q = 2; q < n; q++ ) {
long pToTheQ = (long) Math.pow(p, q);
if (pToTheQ > n) {
break;
}
if (pToTheQ == n) {
System.out.printf("Woo-hoo! %d^%d == %d", p, q, n);
return true;
}
}
}
return false;
}
Another text-based (and therefore not efficient or elegant) answer in java.
This compiles and works, but dies for A >= 396. (Interview question: why?)
public static long findCoolNumber(int a) {
for (long result = 1; result < Long.MAX_VALUE; result++) {
String binValue = Long.toBinaryString(result);
long toDecimal = Long.parseLong(binValue);
if ((toDecimal % a) == 0) {
return toDecimal;
}
}
return 0; // or other sentinal, or throw exception if you like.
}
The answer is indeterminate.
- auricoso2000 March 30, 2015The spawning thread sets MyClass.flag to true, then updates MyClass.num without any synchronization. Thus MyThread might awaken and execute at any point between or after MyClass sets MyClass.num -- or even during.