Count in factors: Difference between revisions

added Sage code example and output
(Added Quackery.)
(added Sage code example and output)
Line 4,087:
20 = 2 x 2 x 5
</pre>
 
=={{header|Sage}}==
<lang python>def count_in_factors(n):
if is_prime(n) or n == 1:
print(n,end="")
return
while n != 1:
p = next_prime(1)
while n % p != 0:
p = next_prime(p)
print(p,end="")
n = n / p
if n != 1: print(" x",end=" ")
 
for i in range(1, 101):
print(i,"=",end=" ")
count_in_factors(i)
print("")</lang>
 
{{out}}
<pre>
1 = 1
2 = 2
3 = 3
4 = 2 x 2
5 = 5
6 = 2 x 3
7 = 7
8 = 2 x 2 x 2
9 = 3 x 3
10 = 2 x 5
11 = 11
12 = 2 x 2 x 3
13 = 13
14 = 2 x 7
15 = 3 x 5
16 = 2 x 2 x 2 x 2
17 = 17
18 = 2 x 3 x 3
19 = 19
20 = 2 x 2 x 5
21 = 3 x 7
22 = 2 x 11
23 = 23
24 = 2 x 2 x 2 x 3
25 = 5 x 5
26 = 2 x 13
27 = 3 x 3 x 3
28 = 2 x 2 x 7
29 = 29
30 = 2 x 3 x 5
31 = 31
32 = 2 x 2 x 2 x 2 x 2
33 = 3 x 11
34 = 2 x 17
35 = 5 x 7
36 = 2 x 2 x 3 x 3
37 = 37
38 = 2 x 19
39 = 3 x 13
40 = 2 x 2 x 2 x 5
41 = 41
...
85 = 5 x 17
86 = 2 x 43
87 = 3 x 29
88 = 2 x 2 x 2 x 11
89 = 89
90 = 2 x 3 x 3 x 5
91 = 7 x 13
92 = 2 x 2 x 23
93 = 3 x 31
94 = 2 x 47
95 = 5 x 19
96 = 2 x 2 x 2 x 2 x 2 x 3
97 = 97
98 = 2 x 7 x 7
99 = 3 x 3 x 11
100 = 2 x 2 x 5 x 5</pre>
 
=={{header|Scala}}==
Anonymous user