CoCalc -- Collaborative Calculation in the Cloud
Sharedsage_worksheets / 2016-11-15-131647.sagewsOpen in CoCalc

Worksheets related to Applied Discrete Structures


n=120
A=n.divisors();A
[1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120]
r={}
for a in A:
    r[a]=filter(lambda b:(b%a==0)and (b//a).is_prime(),A)
r
{1: [2, 3, 5], 2: [4, 6, 10], 3: [6, 15], 4: [8, 12, 20], 5: [10, 15], 6: [12, 30], 8: [24, 40], 10: [20, 30], 12: [24, 60], 15: [30], 40: [120], 20: [40, 60], 24: [120], 120: [], 60: [120], 30: [60]}
DiGraph(r).plot()
R=DiGraph(r).adjacency_matrix();R
[0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0] [0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0] [0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0] [0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0] [0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0] [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
R*R
[0 0 0 1 0 2 0 2 0 2 0 0 0 0 0 0] [0 0 0 0 0 0 1 0 2 0 2 0 2 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 2 0 2 2 0] [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