問題一覧 > 通常問題

No.3559 +A,-B

レベル : / AI推定難易度 : 1600 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 30
作問者 : yaaya / テスター : 👑 みうね fluorine TKTYI HoyHoyCharhang jastaway soryuusi0219 butsurizuki wasab1 tatesoto KumaTachiRen
お気に入りにしたユーザー ProblemId : 13381 / 自分の提出
問題文最終更新日: 2026-08-15 03:18:31
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
KCPC新歓杯2026 (順位表) の他の問題:

Problem Statement

You are given $T$ test cases.

For each test case, you are given integers $N, X, Y, A, B$. Output $f^N(X, Y)$.

Here, $f^N(X,Y)$ is defined as follows:

  • If $X+Y<0$, then $f(X,Y)=(X+A,Y)$
  • If $X+Y\ge 0$, then $f(X,Y)=(X,Y-B)$
  • If $N=1$, then $f^N(X, Y)=f(X,Y)$
  • If $N\ge 2$, then $f^N(X,Y)=f(f^{N-1}(X,Y))$

Input

The input is given from standard input in the following format.

$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$

Each test case is given in the following format.

$N$ $X$ $Y$ $A$ $B$
  • $1\le T\le 10^5$
  • $1\le N\le 10^9$
  • $|X|, |Y|, |A|, |B| \le 10^9$
  • All input values are integers.

Output

Output $T$ lines.
On the $i$-th line, for the answer $f^N(X,Y)=(P,Q)$ to the $i$-th test case, output $P$,$Q$ separated by a space.

Partial Score

This problem has partial scoring based on subtasks.

SubtaskScoreConstraints
部分点110% (25 pts)$N \leq 10$
部分点260% (150 pts)$0<A$ かつ $0<B$
部分点330% (75 pts)追加の制約はない

Sample

Sample 1
Input
3
3 -3 2 1 1
5 3 4 -3 4
4 -1 0 5 3
Output
-1 1
-6 -4
9 -6

In the $1$st test case, $A=B=1$, and $f(-3,2)=(-2,2),f(-2,2)=(-2,1),f(-2,1)=(-1,1)$.
Therefore, $f^3(-3,2)=f(f^2(-3,2))=f(f(f(-3,2)))=f(f(-2,2))=f(-2,1)=(-1,1)$.

Sample 2
Input
3
1000 -10000000 100 1 1
3141592 6535 8979 3238 4626
1024 2048 4096 8192 16384
Output
-9999000 100
5983960055 -5983962573
5588992 -5599232

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。