Advertisement
Guest User

Untitled

a guest
May 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <NTL/ZZ.h>
  4. #include <NTL/mat_ZZ.h>
  5. using namespace NTL;
  6. using namespace std;
  7.  
  8. void fermat(ZZ n, ZZ p)
  9. {
  10. ZZ m, d1, d2, A, B, b, x;
  11. cout << "p/n ";
  12. if (n%p == 0)
  13. cout << "division succeeded. Divider is " << p;
  14. else
  15. {
  16. cout << "division failed. Factorization: " << endl;
  17. m = SqrRoot(n^2);
  18. for (x = 0; x < m; x++)
  19. {
  20. A = m + x;
  21. b = (A*A) - n;
  22. B = SqrRoot(b^2);
  23. d1 = A + B;
  24. d2 = A - B;
  25. /*cout << "m = " << m << endl;
  26. cout << "A = " << A << endl;
  27. cout << "b = " << b << endl;
  28. cout << "B = " << B << endl;
  29. cout << "d1 = " << d1 << endl;
  30. cout << "d2 = " << d2 << endl;
  31. cout << "d1*d2 = " << d1*d2 << endl;*/
  32. if (d1*d2 == n)
  33. cout << d1 << " and " << d2 << endl;
  34. }
  35. }
  36. }
  37.  
  38. int main()
  39. {
  40. ZZ n, p;
  41. cout << "n = ";
  42. cin >> n;
  43. cout << "(Must be prime!) p = ";
  44. cin >> p;
  45. fermat(n, p);
  46. cout << endl;
  47. system("pause");
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement