Created
June 23, 2013 18:05
-
-
Save st0le/5845933 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Scanner; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.Future; | |
public class Main implements Callable<Integer> { | |
private int Z, I, M, L; | |
public Main(int z, int i, int m, int l) { | |
Z = z; | |
I = i; | |
M = m; | |
L = l; | |
} | |
public static void main(String[] args) throws Exception { | |
ExecutorService pool = Executors.newFixedThreadPool(20); | |
List<Future<Integer>> results = new ArrayList<Future<Integer>>(); | |
Scanner scan = new Scanner(System.in); | |
while (scan.hasNext()) { | |
int Z = scan.nextInt(), I = scan.nextInt(), M = scan.nextInt(), L = scan | |
.nextInt(); | |
if(Z==0 && I == 0 && M == 0 && L == 0) break; | |
results.add(pool.submit(new Main(Z, I, M, L))); | |
} | |
int t = 1; | |
for (Future<Integer> f : results) { | |
System.out.println(String.format("Case %d: %d", t++, f.get())); | |
} | |
pool.shutdown(); | |
} | |
@Override | |
public Integer call() throws Exception { | |
int l2 = L; | |
int c = 0; | |
do | |
{ | |
L = (Z * L + I) % M; | |
l2 = (Z * l2 + I) % M; | |
l2 = (Z * l2 + I) % M; | |
c++; | |
}while(l2 != L); | |
return c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment