1 changed files with 38 additions and 0 deletions
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
public class FindBlues { |
||||
|
||||
public static void main(String[] args) { |
||||
findSolutions((long)(1E12)); |
||||
} |
||||
|
||||
/** Find solutions to the problem of |
||||
* how many blue records to have so that |
||||
* two blue records taken at random have |
||||
* 50% probability. |
||||
*/ |
||||
public static void findSolutions(long originalN) { |
||||
long N = originalN; |
||||
int count = 0; |
||||
boolean done = false; |
||||
while(!done) { |
||||
N++; |
||||
count++; |
||||
long operand = 2*N*(N-1)+1; |
||||
long squirt = (long)(Math.sqrt(operand)); |
||||
if(squirt*squirt == operand) { |
||||
if(squirt%2==1) { |
||||
System.out.println("Found solution."); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
long operand = 2*N*(N-1)+1; |
||||
long NB = (long)(Math.sqrt(operand)); |
||||
System.out.println("N:\t"+N); |
||||
System.out.println("NB:\t"+NB); |
||||
|
||||
// Nope....
|
||||
|
||||
} |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue