Codeforces-959D Mahmoud and Ehab and another array construction task(贪心)_a. ehab and another construction problem-CSDN博客

网站介绍:文章浏览阅读513次。题意:给定数组a,求大于或者等于数组a字典序的数组b,满足任意i,j,gcd(bi, bj) = 1。并且是在所有满足条件中的字典序最小的一个。思路:任意一对数互质,可以通过标记其质因子来解决,在找到第一个违背互质的数时,只需要找出大于该数的最小的一个与前面所有数互质的数,在此之后,要想保证字典序最小,便是所有可用的质数从小向大取。代码:#include using name_a. ehab and another construction problem