実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
正整数 A,B が与えられます。
A+B を(十進法で)計算する時、繰り上がりが生じないなら Easy 、生じるなら Hard と出力してください。
制約
- A,B は整数
- 1 \le A,B \le 10^{18}
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
繰り上がりが生じないなら Easy 、生じるなら Hard と出力せよ。
入力例 1
229 390
出力例 1
Hard
229+390 を計算する際、十の位から百の位へと繰り上がりが発生します。よって、答えは Hard です。
入力例 2
123456789 9876543210
出力例 2
Easy
繰り上がりは発生しません。答えは Easy です。
また、入力が 32bit 整数に収まらないこともあります。
Score : 200 points
Problem Statement
You are given positive integers A and B.
Let us calculate A+B (in decimal). If it does not involve a carry, print Easy; if it does, print Hard.
Constraints
- A and B are integers.
- 1 \le A,B \le 10^{18}
Input
Input is given from Standard Input in the following format:
A B
Output
If the calculation does not involve a carry, print Easy; if it does, print Hard.
Sample Input 1
229 390
Sample Output 1
Hard
When calculating 229+390, we have a carry from the tens digit to the hundreds digit, so the answer is Hard.
Sample Input 2
123456789 9876543210
Sample Output 2
Easy
We do not have a carry here; the answer is Easy.
Note that the input may not fit into a 32-bit integer.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
正の整数 X に対して、X を 2 進表記したときに 末尾 に連続する 0 の個数(の最大値)を \text{ctz}(X) で表します。
ただし、X を 2 進表記したとき末尾が 1 ならば \text{ctz}(X)=0 です。
正の整数 N が与えられるので、\text{ctz}(N) を出力してください。
制約
- 1\leq N\leq 10^9
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
\text{ctz}(N) を出力せよ。
入力例 1
2024
出力例 1
3
2024 を 2 進表記すると 11111101000 であり、末尾から 0 が 3 個連続しているため、\text{ctz}(2024)=3 です。
よって、3 を出力します。
入力例 2
18
出力例 2
1
18 を 2 進表記すると 10010 であるため、\text{ctz}(18)=1 です。
0 は末尾から連続する必要があることに注意してください。
入力例 3
5
出力例 3
0
Score: 200 points
Problem Statement
For a positive integer X, let \text{ctz}(X) be the (maximal) number of consecutive zeros at the end of the binary notation of X.
If the binary notation of X ends with a 1, then \text{ctz}(X)=0.
You are given a positive integer N. Print \text{ctz}(N).
Constraints
- 1\leq N\leq 10^9
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print \text{ctz}(N).
Sample Input 1
2024
Sample Output 1
3
2024 is 11111101000 in binary, with three consecutive 0s from the end, so \text{ctz}(2024)=3.
Thus, print 3.
Sample Input 2
18
Sample Output 2
1
18 is 10010 in binary, so \text{ctz}(18)=1.
Note that we count the trailing zeros.
Sample Input 3
5
Sample Output 3
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
あなたはアメーバの観察記録をつけました。
最初 1 匹のアメーバがおり、番号は 1 です。
観察記録は時系列順に N 個あり、i 番目の観察記録は「番号 A_i のアメーバが分裂して消滅し、新たに 2 匹のアメーバが生まれ、それらにそれぞれ 2i,2i+1 と番号をつけた」というものです。
このとき、アメーバ A_i を アメーバ 2i,2i+1 の親と呼びます。
各 k=1,\ldots,2N+1 について、アメーバ k から何代親を遡るとアメーバ 1 になるか求めてください。
制約
- 1 \leq N \leq 2\times 10^5
- 観察記録は矛盾していない。すなわち
- 1\leq A_i \leq 2i-1
- A_i は相異なる整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
2N+1 行出力せよ。k 行目にはアメーバ k から何代親を遡るとアメーバ 1 になるかを出力せよ。
入力例 1
2 1 2
出力例 1
0 1 1 2 2
アメーバ 1 からアメーバ 2,3 が生まれ、アメーバ 2 からアメーバ 4,5 が生まれました。
- アメーバ 1 は 0 代遡るとアメーバ 1 になります。
- アメーバ 2 は 1 代遡るとアメーバ 1 になります。
- アメーバ 3 は 1 代遡るとアメーバ 1 になります。
- アメーバ 4 は 1 代遡るとアメーバ 2 になり、2 代遡るとアメーバ 1 になります。
- アメーバ 5 は 1 代遡るとアメーバ 2 になり、2 代遡るとアメーバ 1 になります。
入力例 2
4 1 3 5 2
出力例 2
0 1 1 2 2 3 3 2 2
Score : 300 points
Problem Statement
You observed amoebae and kept some records.
Initially, there was one amoeba, numbered 1.
You made N records. According to the i-th record, the amoeba numbered A_i disappeared by dividing itself into two new amoebae, which were then numbered 2i and 2i+1.
Here, amoeba A_i is said to be the parent of amoebae 2i and 2i+1.
For each k=1,\ldots,2N+1, how many generations away is amoeba k from amoeba 1?
Constraints
- 1 \leq N \leq 2\times 10^5
- The records are consistent. That is:
- 1\leq A_i \leq 2i-1.
- A_i are distinct integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print 2N+1 lines. The k-th line should contain the generation distance between amoeba 1 and amoeba k.
Sample Input 1
2 1 2
Sample Output 1
0 1 1 2 2
From amoeba 1, amoebae 2 and 3 were born. From amoeba 2, amoebae 4 and 5 were born.
- Amoeba 1 is zero generations away from amoeba 1.
- Amoeba 2 is one generation away from amoeba 1.
- Amoeba 3 is one generation away from amoeba 1.
- Amoeba 4 is one generation away from amoeba 2, and two generations away from amoeba 1.
- Amoeba 5 is one generation away from amoeba 2, and two generations away from amoeba 1.
Sample Input 2
4 1 3 5 2
Sample Output 2
0 1 1 2 2 3 3 2 2
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
正整数 D が与えられます。
非負整数 x,y に対する |x^2+y^2-D| の最小値を求めてください。
制約
- 1\leq D \leq 2\times 10^{12}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
D
出力
答えを出力せよ。
入力例 1
21
出力例 1
1
x=4,y=2 のとき |x^2+y^2-D| = |16+4-21|=1 となります。
|x^2+y^2-D|=0 を満たすような非負整数 x,y は存在しないので、答えは 1 です。
入力例 2
998244353
出力例 2
0
入力例 3
264428617
出力例 3
32
Score : 300 points
Problem Statement
You are given a positive integer D.
Find the minimum value of |x^2+y^2-D| for non-negative integers x and y.
Constraints
- 1\leq D \leq 2\times 10^{12}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
D
Output
Print the answer.
Sample Input 1
21
Sample Output 1
1
For x=4 and y=2, we have |x^2+y^2-D| = |16+4-21|=1.
There are no non-negative integers x and y such that |x^2+y^2-D|=0, so the answer is 1.
Sample Input 2
998244353
Sample Output 2
0
Sample Input 3
264428617
Sample Output 3
32
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
正整数 A,B が与えられます。
あなたは、A=B になるまで以下の操作を繰り返します。
- A,B の大小関係に応じて、次の 2 個のうちどちらかの処理を行う。
- A > B ならば、A を A-B で置き換える。
- A < B ならば、B を B-A で置き換える。
A=B になるまで、操作を何回行うか求めてください。ただし、有限回の操作で A=B になることが保証されます。
制約
- 1 \le A,B \le 10^{18}
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを出力せよ。
入力例 1
3 8
出力例 1
4
始め、A=3,B=8 です。操作は以下のように行われます。
- A<B であるため、B を B-A=5 で置き換える。A=3,B=5 となる。
- A<B であるため、B を B-A=2 で置き換える。A=3,B=2 となる。
- A>B であるため、A を A-B=1 で置き換える。A=1,B=2 となる。
- A<B であるため、B を B-A=1 で置き換える。A=1,B=1 となる。
よって、操作回数は 4 回です。
入力例 2
1234567890 1234567890
出力例 2
0
入力が 32bit 整数型に収まらないことがあることに注意してください。
入力例 3
1597 987
出力例 3
15
Score : 400 points
Problem Statement
You are given positive integers A and B.
You will repeat the following operation until A=B:
- compare A and B to perform one of the following two:
- if A > B, replace A with A-B;
- if A < B, replace B with B-A.
How many times will you repeat it until A=B? It is guaranteed that a finite repetition makes A=B.
Constraints
- 1 \le A,B \le 10^{18}
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer.
Sample Input 1
3 8
Sample Output 1
4
Initially, A=3 and B=8. You repeat the operation as follows:
- A<B, so replace B with B-A=5, making A=3 and B=5.
- A<B, so replace B with B-A=2, making A=3 and B=2.
- A>B, so replace A with A-B=1, making A=1 and B=2.
- A<B, so replace B with B-A=1, making A=1 and B=1.
Thus, you repeat it four times.
Sample Input 2
1234567890 1234567890
Sample Output 2
0
Note that the input may not fit into a 32-bit integer type.
Sample Input 3
1597 987
Sample Output 3
15