0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ABC - 106- A&B&C

Posted at

AtCoder ABC 106 A&B&C

AtCoder - 106

A問題

  • 縦横からそれぞれ-1して算出
	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();

			System.out.println((numA - 1) * (numB - 1));

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

B問題

  • その数の約数を全て調べる
	private void solveB2() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			int count = 0;
			/*
			 * 1からNまでの数値を全探索
			 */
			for (int i = 1; i <= numN; i++) {
				if (i % 2 == 0) {
					continue;
				}
				int wkRes = 0;
				/*
				 * 数値iが、約数をいくつ持つのか調べる
				 * 最大でもNまで(i<=Nだし)
				 * 自身も約数だということを忘れずに
				 */
				for (int j = 1; j <= numN; j++) {
					if (j % 2 == 0) {
						continue;
					}
					if (i % j == 0) {
						wkRes++;
					}
				}
				if (wkRes == 8) {
					count++;
				}
			}

			System.out.println(count);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

C問題

  • $1$は$5000兆日後$も$1$のままだが、$2$は$2^{5000兆}$となるので計算は無理
  • 文字列がK番目まですべて$1$なら$5000兆日後$もK番目は$1$だけど、その間に$2以上の数値$が入っていればその数値になる
    • 文字列を$K番目$まで調べていって、$1$以外が出現したらその数値が$5000兆日後$の$K番目$
    • $1$のみだったら$5000兆日後$の$K番目$は$1$
private void solveC() {
		Scanner scanner = null;
		String wkS;
		long count = 0;

		try {
			scanner = new Scanner(System.in);
			wkS = scanner.next();
			count = scanner.nextLong();
			String wk = wkS;
			if (count <= wkS.length()) {
				wk = wkS.substring(0, (int) count);
			}
			for (int i = 0; i < wk.length(); i++) {
				if (wk.charAt(i) != '1') {
					System.out.println(wk.charAt(i));
					return;
				}
			}
			System.out.println(1);
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?