Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package daa;
  7. import java.math.BigInteger;
  8. /**
  9. *
  10. * @author student
  11. */
  12. public class Daa {
  13.  
  14.  
  15. /**
  16. * @param args the command line arguments
  17. */
  18. //recursively searches for the sqr root of a in interval [left, right]
  19. private static BigInteger NaiveSquareRootSearch(BigInteger a, BigInteger left,BigInteger right)
  20. {
  21. // fix root as the arithmetic mean of left and right
  22. BigInteger root = left.add(right).shiftRight(1);
  23. // if the root is not between [root, root+1],
  24. //is not an integer and root is our best integer approximation
  25. if(!((root.pow(2).compareTo(a) == -1)&&(root.add(BigInteger.ONE).pow(2).compareTo(a) == 1))){
  26. if (root.pow(2).compareTo(a) == -1) root = NaiveSquareRootSearch(a, root,right);
  27. if (root.pow(2).compareTo(a) == 1) root = NaiveSquareRootSearch(a, left,root);
  28. }
  29. return root;
  30. }
  31.  
  32. public static BigInteger SquareRoot(BigInteger a)
  33. {
  34. return NaiveSquareRootSearch(a, BigInteger.ZERO, a);
  35. }
  36. public static void main(String[] args) {
  37.  
  38. // TODO code application logic here
  39. BigInteger n= new BigInteger ("5076313634899413540120536350051034312987619378778911504647420938544746517711031490115528420427319479274407389058253897498557110913160302801741874277608327");
  40. BigInteger e= new BigInteger ("3");
  41. BigInteger d= new BigInteger ("3384209089932942360080357566700689541991746252519274336431613959029831011807259226655786125050887727921274719751986104162037800807641522348207376583379547");
  42. BigInteger zero= new BigInteger ("0");
  43. BigInteger unu= new BigInteger ("1");
  44. BigInteger doi= new BigInteger ("2");
  45. BigInteger patru= new BigInteger ("4");
  46. BigInteger k;
  47. if(((((d.multiply(e)).subtract(unu)).mod(n)).equals(zero))){
  48. k = ((((d.multiply(e)).subtract(unu)).divide(n)));
  49. }
  50. else{
  51. k = ((((d.multiply(e)).subtract(unu)).divide(n))).add(unu);
  52. }
  53. System.out.println("K = " + k);
  54. BigInteger sum = ((((n.add(unu)).multiply(k)).add(unu)).subtract(e.multiply(d))).divide(k);
  55. BigInteger del = (sum.pow(2)).subtract(patru.multiply(n));
  56. BigInteger radical = SquareRoot(del);
  57. BigInteger x1 = (sum.add(radical)).divide(doi);
  58. System.out.println("x1 = " + x1);
  59. BigInteger x2 = (sum.subtract(radical)).divide(doi);
  60. System.out.println("x2 = " + x2);
  61. BigInteger pro = x1.multiply(x2);
  62. System.out.println("x1*x2 = " + pro);
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement