prime_factorization_concept.pl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 06 July 2015
  5. # Website: https://github.com/trizen
  6. # Prime factorization in polynomial time (concept only)
  7. use 5.010;
  8. use strict;
  9. use warnings;
  10. #
  11. ## The backwards process of:
  12. #
  13. # 23 *
  14. # 17
  15. # ----
  16. # 161
  17. # 23
  18. # -----
  19. # 391
  20. # 23
  21. my $x2 = 2;
  22. my $x1 = 3;
  23. # 17
  24. my $y2 = 1;
  25. my $y1 = 7;
  26. # {
  27. # 1=10*(a*c/10-floor(a*c/10)),
  28. # 9=10*(b*c/10-floor(b*c/10))+floor(a*c/10)+10*(a*d/10-floor(a*d/10)),
  29. # 3=floor((b*c+floor(a*c/10))/10)+10*(b*d/10-floor(b*d/10))
  30. # }
  31. # Last digit
  32. say(($x1 * $y1) % 10);
  33. # Middle digit
  34. say((($x2 * $y1) % 10) + int($x1 * $y1 / 10) + (($x1 * $y2) % 10));
  35. # First digit
  36. say(int((($x2 * $y1) + int($x1 * $y1 / 10)) / 10) + (($x2 * $y2) % 10));
  37. #
  38. ## Alternate forms:
  39. #
  40. say "-" x 80;
  41. # Last digit
  42. say(($x1 * $y1 / 10 - int($x1 * $y1 / 10)) * 10);
  43. # Middle digit
  44. say(int($x1 * $y1 / 10) - 10 * int($x1 * $y2 / 10) + $x1 * $y2 - 10 * int($x2 * $y1 / 10) + $x2 * $y1);
  45. # First digit
  46. say(int($x2 * $y1 / 10 + int($x1 * $y1 / 10) / 10) + 10 * ($x2 * $y2 / 10 - int($x2 * $y2 / 10)));