알고리즘/SW Expert Academy

[D3] 8104. 조 만들기

혬혬 2019. 10. 6. 11:03
728x90
#include <stdio.h>

int main() {

	int test_case = 0;
	scanf("%d", &test_case);
	for (int q = 0; q < test_case; q++) {
		int N = 0;
		int K = 0;
		scanf("%d %d", &N, &K);
		printf("#%d ",q+1);
		if (N % 2 != 0) {
			int box = (N+1)*K;
			int box1 = (N + 1)*K;
			box = (box*(box + 1)) / (2 * K);
			for (int i = 0; i < K; i++) {
				printf("%d ", box-box1);
				box1--;
			}
		}
		else {
			int box = N*K;
			box = (box*(box + 1)) / (2 * K);
			for (int i = 0; i < K; i++) {
				printf("%d ", box);
			}
		}
		printf("\n");
	}

	return 0;
}
728x90