結果

問題 No.915 Plus Or Multiple Operation
ユーザー htensaihtensai
提出日時 2020-06-10 17:52:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 784 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 75,508 KB
実行使用メモリ 54,348 KB
最終ジャッジ日時 2024-04-24 18:57:31
合計ジャッジ時間 4,034 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 103 ms
39,928 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
 	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    StringBuilder sb = new StringBuilder();
	    for (int i = 0; i < n; i++) {
	        int a = sc.nextInt();
	        long b = sc.nextInt();
	        int c = sc.nextInt();
	        if (c == 1) {
	            sb.append(-1).append("\n");
	        } else {
	            sb.append(getCount(a, c) * b).append("\n");
	        }
	    }
	    System.out.print(sb);
	}
	
	static int getCount(int x, int y) {
	    if (x == 0) {
	        return 0;
	    } else if (x % y == 0) {
	        return getCount(x / y, y) + 1;
	    } else if ((y - 1) * 2 >= x) {
	        return 2;
	    } else {
	        return getCount(x - x % y, y) + 1;
	    }
	}
}
0