hiho week 167 register

Ended

Participants:334

Verdict:Accepted
Score:100 / 100
Submitted:2017-09-10 19:05:40

Lang:Python2

Edit
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
while True:
    try:
        def gcd(ab):
            r = a % b
            if r:
                return gcd(br)
            else:
                return b
            #print gcd(13, 6)
        def lcm(ab):
            return a * b / gcd(ab)
        #print lcm(12, 6)
        def lcmAll(seq):
            return reduce(lcmseq)
        n = int(raw_input())
        num = [int(i) for i in raw_input().split()]
        a = []
        for i in range(n):
            cnt = 0
            t = i
            while num[i] != t + 1:
                cnt += 1
                i = num[i] - 1
            a.append(cnt+1)
        print lcmAll(a)
    except:
        break
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX