fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. long[] seed = new long[1000000];
  14. seed[0] = 0x9876_5432L;
  15. seed[1] = 0xF1E2_D3C4L;
  16. int[][] t = new int[8][16];
  17. Map<Long, Integer> map = new TreeMap<Long, Integer>();
  18. map.put(seed[0], 0);
  19. map.put(seed[1], 1);
  20. int last = seed.length, first = 0;
  21. for (int i = 2; i < seed.length; i++)
  22. {
  23. seed[i] = seed[i - 2] ^ (seed[i - 1] >> ((i - 1) & 0xF)) ^ (seed[i - 1] << ((i + i + 1) & 0xF));
  24. seed[i] &= 0xFFFF_FFFFL;
  25. long e = seed[i];
  26. if (map.containsKey(e)) {
  27. first = map.get(e);
  28. last = i;
  29. System.out.println("cycle: " + map.get(e) + " to " + (i - 1) + " len " + (i - map.get(e)));
  30. break;
  31. }
  32. map.put(e, i);
  33. if (e == 0L) throw new RuntimeException("ZERO!! " + i);
  34. }
  35. for (int i = first; i < last; i++)
  36. {
  37. long e = seed[i];
  38. for (int j = 0; j < 8; j++)
  39. {
  40. t[j][(int)(e & 0xFL)]++;
  41. e >>= 4;
  42. }
  43. }
  44. System.out.println("length: " + seed.length);
  45. System.out.println("unique: " + map.size());
  46. System.out.printf("last: %8x%n", seed[last - 1]);
  47. for (int i = 0; i < 8; i++)
  48. {
  49. int m = 0;
  50. for (int j = 0; j < 16; j++)
  51. {
  52. m = Math.max(m, t[i][j]);
  53. }
  54. for (int j = 0; j < 16; j++)
  55. {
  56. System.out.printf("%3d ", 100 * t[i][j] / m);
  57. }
  58. System.out.println();
  59. }
  60. }
  61. }
Success #stdin #stdout 0.35s 58768KB
stdin
Standard input is empty
stdout
cycle: 51117 to 128824 len 77708
length: 1000000
unique: 128825
last: 28fd228b
 96  99 100  99  96  96  97  97  99  97  97  96  96  96  97  95 
 96  96 100  96  96  95  96  97  97  98  99  96  98  95  96  97 
 98  99  99  98  96  98  95  98 100  96  97  98  98  97  98  96 
 97  97  96  95  97  96  97  98  95  99 100  99  99  97  98  96 
 96  98  97  95  97  95  97  96  98  96 100  99  97  96  96  94 
 97  95 100  98  99  97  99  99  96  97  96  97  98  98  99  99 
 98  99  97  98  97  99  95  98  94  97  95  96  99  97  99 100 
100  97  95  97  97  98  98  97  98  96  99  97  95  97  98  97