Good Sequences(codeforces 264B)

这是一道关于寻找最长递增子序列的问题,序列中相邻元素的最大公约数必须大于1。需要找到这样的序列并输出其长度。题解涉及动态规划和质因数分解,其中关键在于正确初始化ans的值和优化质因数分解的范围。
摘要由CSDN通过智能技术生成

题目:
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, …, an are good.

Now she is interested in good sequences. A sequence x1, x2, …, xk is called good if it satisfies the following three conditions:

  • The sequence is strictly increasing, i.e. xi < xi + 1 for each i
    (1 ≤ i ≤ k - 1).
  • No two adjacent elements are coprime, i.e. gcd(xi, xi + 1) > 1 for
    each i (1 ≤ i ≤ k - 1) (where gcd(p, q) denotes the greatest
    common divisor of the integers p and q).
  • All elements of the sequence are good integers.

Find the length of the longest good sequence.

input
The input consists of two lines. The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of good integers. The second line contains a single-space separated list of good integers a1, a2, …, an in strictly increasing order

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值