import java.util.Scanner;
public class NeumannsRandomGenerator {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter cases:");
int cases = in.nextInt();
int iterations = 0;
for (int i = 0; i <= cases; i++) {
int a = in.nextInt();
int res = ((a * a) / 100) % 10000;
if(res == a){
iterations++;
}
do {
int b = ((res * res) / 100) % 10000;
iterations++;
b = res;
} while (a != res);
System.out.println(iterations);
}
}
}
I am trying to figure Neumans random generator For Example:
5761 - let it be the first number
5761 * 5761 = 33189121 - raised to power 2
33(1891)21 => 1891 - truncate to get the middle
1891 - it is the second number in the sequence
1891 * 1891 = 3575881 - raised to power 2 (add leading zero to get 8 digits)
03(5758)81 => 5758 - truncate to get the middle
5758 - it is the third number in the sequence (and so on...)
Please help why I am not getting any results:(