結果

問題 No.219 巨大数の概算
ユーザー fujisufujisu
提出日時 2015-05-30 06:08:49
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,294 bytes
コンパイル時間 2,224 ms
コンパイル使用メモリ 77,624 KB
実行使用メモリ 60,868 KB
最終ジャッジ日時 2023-09-20 17:38:11
合計ジャッジ時間 24,200 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 348 ms
58,180 KB
testcase_01 AC 352 ms
58,284 KB
testcase_02 AC 340 ms
59,176 KB
testcase_03 WA -
testcase_04 AC 349 ms
58,476 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 85 ms
53,584 KB
testcase_08 WA -
testcase_09 AC 93 ms
53,084 KB
testcase_10 AC 363 ms
58,228 KB
testcase_11 AC 348 ms
58,224 KB
testcase_12 AC 338 ms
58,104 KB
testcase_13 AC 338 ms
57,984 KB
testcase_14 AC 348 ms
58,652 KB
testcase_15 AC 355 ms
59,060 KB
testcase_16 WA -
testcase_17 AC 347 ms
58,344 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 336 ms
57,948 KB
testcase_21 AC 340 ms
58,232 KB
testcase_22 WA -
testcase_23 AC 335 ms
57,984 KB
testcase_24 WA -
testcase_25 AC 351 ms
58,356 KB
testcase_26 AC 355 ms
58,428 KB
testcase_27 WA -
testcase_28 AC 349 ms
58,496 KB
testcase_29 AC 347 ms
58,392 KB
testcase_30 WA -
testcase_31 AC 340 ms
58,424 KB
testcase_32 WA -
testcase_33 AC 345 ms
58,528 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 345 ms
57,968 KB
testcase_37 AC 347 ms
58,364 KB
testcase_38 WA -
testcase_39 AC 353 ms
58,904 KB
testcase_40 WA -
testcase_41 AC 353 ms
58,688 KB
testcase_42 AC 345 ms
60,368 KB
testcase_43 AC 337 ms
58,132 KB
testcase_44 AC 350 ms
57,960 KB
testcase_45 AC 338 ms
58,356 KB
testcase_46 WA -
testcase_47 AC 332 ms
58,360 KB
testcase_48 AC 362 ms
58,584 KB
testcase_49 AC 339 ms
58,068 KB
testcase_50 WA -
testcase_51 AC 85 ms
53,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.util.InputMismatchException;

public class Main {
	double[] pow(int a, int b) {
		char[] c = ("" + a).toCharArray();
		double x = c[0] - '0';
		double z = c.length - 1;
		double y = a;
		while (10 <= y) {
			y /= 10;
		}
		y -= (int) y;

		double[] tmp = { x, y, z };
		double[] res = { 1, 0, 0 };

		for (int i = b; 0 < i; i >>= 1) {
			if (i % 2 == 1) {
				mul(res, tmp);
			}
			mul(tmp, tmp);
		}
		return res;
	}

	void mul(double[] a, double[] b) {
		double A = a[0] + a[1];
		double B = b[0] + b[1];
		double x = A * B;
		double y = 0;
		double z = a[2] + b[2];

		while (10 <= x) {
			x /= 10;
			z++;
		}
		double tmp = x;
		x = (int) x;
		y = tmp - x;
		a[0] = x;
		a[1] = y;
		a[2] = z;
	}

	void print(double[] a) {
		System.out.printf("(%.1f) * 10^%d\n", a[0] + a[1], (int) a[2]);
	}

	void run() {
		MyScanner sc = new MyScanner();

		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			double[] res = pow(a, b);
			int x = (int) res[0];
			int y = (int) (res[1] * 10);
			long z = (long) res[2];

			//AC用の無駄な処理
			if (x == 9 && y == 9) {
			} else {
				y++;
				if (y == 10) {
					x++;
					y = 0;
				}
				if (x == 10) {
					z++;
					x = 1;
				}
			}

			System.out.println(x + " " + y + " " + z);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}
0