357 名前:h_object([1]) do |i, a| x = (a.last * n % m) ind = a.index(x) ind.nil? ? a.push(x) : (break([ind, i - ind])) end x = n.times.reduce(1){|r, i| r *= n; r < index ? r : break} y = x.nil? ? index + (powmod(n, n, cycle) - index) % cycle : x powmod(n, y, m) end