codeforces 1878B. Aleksa and Stack

题目如下
After the Serbian Informatics Olympiad, Aleksa was very sad, because he didn't win a medal (he didn't know stack), so Vasilije came to give him an easy problem, just to make his day better.

Vasilije gave Aleksa a positive integer 𝑛 (𝑛≥3) and asked him to construct a strictly increasing array of size 𝑛 of positive integers, such that

3⋅𝑎𝑖+2 is not divisible by 𝑎𝑖+𝑎𝑖+1 for each 𝑖 (1≤𝑖≤𝑛−2).
Note that a strictly increasing array 𝑎 of size 𝑛 is an array where 𝑎𝑖<𝑎𝑖+1 for each 𝑖 (1≤𝑖≤𝑛−1).
Since Aleksa thinks he is a bad programmer now, he asked you to help him find such an array.

Input
Each test consists of multiple test cases. The first line contains a single integer 𝑡 (1≤𝑡≤104) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer 𝑛 (3≤𝑛≤2⋅105) — the number of elements in array.

It is guaranteed that the sum of 𝑛 over all test cases does not exceed 2⋅105.

Output
For each test case, output 𝑛 integers 𝑎1,𝑎2,𝑎3,…,𝑎𝑛 (1≤𝑎𝑖≤109).

It can be proved that the solution exists for any 𝑛. If there are multiple solutions, output any of them.

题目大意
题目很长,大概就是让我们构造一个后项不能被前项整除的数组

解题思路
所以,这里有很多种方法来构造,比如说,只要让前项和后项成奇偶交错即可,保证了数组的构造

代码

点击查看代码
#include <stdio.h>

int main() {
    int t;
    scanf("%d", &t);
    while (t--){
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            printf("%d ",i * 2 + 1);  // 奇数和偶数交错来保证不能整除
        }
        printf("\n");
    }
    return 0;
}
posted @ 2025-07-01 20:43  sirro1uta  阅读(14)  评论(0)    收藏  举报