class SegmentTree(initial: List) { private val half = ceilPow2(initial.size) private val vec = LongArray(half * 2) init { for (i in initial.indices) { vec[half + i] = initial[i] } for (i in half - 1 downTo 1) { vec[i] = gcd(vec[i * 2], vec[i * 2 + 1]) } } fun get(from: Int, until: Int): Long { check(from in vec.indices && until in 0 .. vec.size) var l = from + half var r = until + half var result = 0L while (l < r) { if (l and 1 == 1) { result = gcd(result, vec[l]) l += 1 } if (r and 1 == 1) { r -= 1 result = gcd(result, vec[r]) } l = l shr 1 r = r shr 1 } return result } companion object { fun ceilPow2(value: Int): Int { var result = 1 while (result < value) { result *= 2 } return result } } } tailrec fun gcd(a: Long, b: Long): Long { return when(b){ 0L -> a else -> gcd(b, a % b) } } fun main() { val n = readLine()!!.trim().toInt() val num = readLine()!!.trim().split(' ').map(String::toLong) val seg = SegmentTree(num) var j = 0 var result = 0L for (i in 0 until n) { var d = seg.get(i, j) while (j in num.indices && d != 1L) { d = gcd(d, num[j]) j += 1 } if (d == 1L) { result += n - j + 1 } } println(result) }