結果

問題 No.311 z in FizzBuzzString
ユーザー marumaru
提出日時 2017-09-27 15:33:46
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 966 bytes
コンパイル時間 3,587 ms
コンパイル使用メモリ 77,588 KB
実行使用メモリ 57,884 KB
最終ジャッジ日時 2023-10-25 02:51:38
合計ジャッジ時間 5,745 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,396 KB
testcase_01 AC 129 ms
57,552 KB
testcase_02 AC 132 ms
57,516 KB
testcase_03 AC 131 ms
57,380 KB
testcase_04 AC 130 ms
57,572 KB
testcase_05 AC 133 ms
57,424 KB
testcase_06 AC 131 ms
57,660 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Fizzbuzz {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int threeAndFive = koubaisuu(5, 3);
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= N; i++) {
			if (i % threeAndFive == 0) {
				sb.append("FizzBuzz");
			} else if (i % 3 == 0) {
				sb.append("Fizz");
			} else if (i % 5 == 0) {
				sb.append("Buzz");
			}
		}
		int count = 0;
		for (int i = 0; i < sb.length(); i++) {
			if (sb.charAt(i) == 'z') {
				count++;
			}
		}
		System.out.println(count);

	}

	// 最大公約数もとめてれる
	private static int saidai(int a, int b) {
		int r;
		while ((r = a % b) != 0) {
			a = b;
			b = r;
		}
		return b;
	}

	//最小公倍数
	private static int koubaisuu(int a ,int b) {
		int gcd = getGCD(a, b);
		return a * b /gcd;
	}
	//最大公倍数
	private static int getGCD(int m, int n) {
		return n == 0 ? m : getGCD(n, m % n);
		}
}
0