This problem can be solved without sorting or a large list of primes by just calculating factors as we concatenate them to a group organized by rad(n)
?View Code PYTHON1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
limit=100000
target=10000
rad={}
buf={}
for i in range(1,limit+1):
rad[i]=1
for j in range(1,limit+1):
buf[j]=""
for i in range(2,limit+1):
if rad[i]==1:
for j in range(i,limit+1,i):
rad[j]=rad[j]*i
hey=rad[i]
buf[hey]=buf[hey]+" "+str(i)
str=""
for i in [...]
To solve this problem you can use regex. However, a simple replacement can also do the trick. According to rules given these replacements are needed to acquire minimal form: DCCCC to CM, LXXXX to XC and VIIII to IX ,IIII to IV, XXXX to XL and CCCC to CD. So the difference in the [...]
Actually, according to stats this one should be relatively hard. However, it can be solved very easily. Probabably, this shows that either people are not good at solving probability problems or they do not like to solve them. Who knows? Here is my code in python. Runs under 1 second.
?View Code PYTHON1
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
import decimal
pdict={}
cdict={}
pcount=0
ccount=0
for i in [...]