Guest User

Untitled

a guest
Apr 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public static int[] smallXGCD(int m, int n, int c){
  2. int[] res = xGCD(m, n, c); //a and b from xGCD.
  3. int[] reshom = homGenXGCD(m, n); //a' and b' from homGenXGCD.
  4. int[] temp = { res[0] + reshom[0] , res[1] + reshom[1] }; //current calculated modulus.
  5. int[] minmod = { res[0] + reshom[0] , res[1] + reshom[1] }; // minimum modulus calculated to the moment.
  6. int[] aux = { 0, 0 };
  7. int sign = 1; //Decides the while's direction.
  8. boolean significant = true;
  9.  
  10. int counter = 1;
  11. while(significant){
  12. counter++;
  13. temp[0] = res[0] + sign*reshom[0]*counter;
  14. temp[1] = res[1] + sign*reshom[1]*counter;
  15. if((Math.abs(temp[0]) + Math.abs(temp[1]) ) < (Math.abs(minmod[0]) + Math.abs(minmod[1]))){
  16. minmod[0] = temp[0];
  17. minmod[1] = temp[1];
  18. }
  19. if((Math.abs(temp[0]) + Math.abs(temp[1]) ) == (Math.abs(minmod[0]) + Math.abs(minmod[1]))){
  20. if(minmod[0] > temp[0]){
  21. minmod[0] = temp[0];
  22. minmod[1] = temp[1];
  23. }
  24. }
  25. if((Math.abs(temp[0]) + Math.abs(temp[1])) > (Math.abs(aux[0]) + Math.abs(aux[1]))){
  26. if(sign == -1)
  27. significant = false;
  28. else{
  29. counter = 1;
  30. sign = -1;
  31. }
  32.  
  33. }
  34. aux[0] = temp[0];
  35. aux[1] = temp[1];
  36. }
  37.  
  38. return minmod;
  39. }
Add Comment
Please, Sign In to add comment