fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
Codeforces Round 1050-A (Div. 4) Sublime Sequence
최초 업로드: 2025-09-13 17:01:25
최근 수정 시간: 2025-09-13 17:01:25
게시자: rlatjwls3333
카테고리: Codeforces
조회수: 61
# A. Sublime Sequence [문제 링크](https://codeforces.com/contest/2148/problem/A) ## Problem Statement Farmer John has an integer $x$. He creates a sequence of length $n$ by alternating integers $x$ and $-x$, starting with $x$. For example, if $n = 5$, the sequence looks like: $x, -x, x, -x, x$. He asks you to find the sum of all integers in the sequence. ## Input The first line contains an integer $t$ ($1 \leq t \leq 100$) — the number of test cases. The only line of input for each test case is two integers $x$ and $n$ ($1 \leq x, n \leq 10$). ## Output For each test case, output the sum of all integers in the sequence. ## 풀이 홀수번째는 x, 짝수번째는 0을 출력하면 됩니다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) { int x, n; cin >> x >> n; if(n%2) cout << x << '\n'; else cout << "0\n"; } } ```