Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void GenerateSequence(int n, int k) {
- if (k > n) { // K must be less than or equal to N
- return;
- }
- int cur = 1;
- int arr[n] = {0};
- for (int i = 0; i < k; i++) {
- arr[i] = cur;
- cur++;
- if (cur > k) { // reset the sequence
- cur = 1;
- }
- }
- for (int i = k; i < n; i++) { // re-create the subarray of length K
- arr[i] = arr[i - k];
- }
- // sample:
- // N = 9, K = 3
- // {1, 2, 3, 1, 2, 3, 1, 2, 3}
- for (int i = 0; i < n; i++) {
- cout << arr[i] << " ";
- }
- cout << '\n';
- }
- int main() {
- int n, k;
- cin >> n >> k;
- GenerateSequence(n, k);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement