結果

問題 No.1869 Doubling?
ユーザー ks2mks2m
提出日時 2022-03-11 22:19:06
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 507 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 74,276 KB
実行使用メモリ 41,392 KB
最終ジャッジ日時 2024-09-16 02:38:04
合計ジャッジ時間 9,690 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

//		if (n == 1) {
//			System.out.println(m);
//			return;
//		}

		int p = m;
		long ans = m;
		for (int i = 1; i < n; i++) {
			if (p == 1) {
				ans += n - i;
				break;
			}
			if (p % 2 == 0) {
				p = p / 2;
			} else {
				p = p / 2 + 1;
			}
			ans += p;
		}
		System.out.println(ans);
	}
}
0