-
Notifications
You must be signed in to change notification settings - Fork 34
/
prime_factorization_concept.pl
executable file
·63 lines (46 loc) · 1.07 KB
/
prime_factorization_concept.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl
# Author: Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 06 July 2015
# Website: https://github.com/trizen
# Prime factorization in polynomial time (concept only)
use 5.010;
use strict;
use warnings;
#
## The backwards process of:
#
# 23 *
# 17
# ----
# 161
# 23
# -----
# 391
# 23
my $x2 = 2;
my $x1 = 3;
# 17
my $y2 = 1;
my $y1 = 7;
# {
# 1=10*(a*c/10-floor(a*c/10)),
# 9=10*(b*c/10-floor(b*c/10))+floor(a*c/10)+10*(a*d/10-floor(a*d/10)),
# 3=floor((b*c+floor(a*c/10))/10)+10*(b*d/10-floor(b*d/10))
# }
# Last digit
say(($x1 * $y1) % 10);
# Middle digit
say((($x2 * $y1) % 10) + int($x1 * $y1 / 10) + (($x1 * $y2) % 10));
# First digit
say(int((($x2 * $y1) + int($x1 * $y1 / 10)) / 10) + (($x2 * $y2) % 10));
#
## Alternate forms:
#
say "-" x 80;
# Last digit
say(($x1 * $y1 / 10 - int($x1 * $y1 / 10)) * 10);
# Middle digit
say(int($x1 * $y1 / 10) - 10 * int($x1 * $y2 / 10) + $x1 * $y2 - 10 * int($x2 * $y1 / 10) + $x2 * $y1);
# First digit
say(int($x2 * $y1 / 10 + int($x1 * $y1 / 10) / 10) + 10 * ($x2 * $y2 / 10 - int($x2 * $y2 / 10)));