結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-04 17:10:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 1,000 ms
コード長 964 bytes
コンパイル時間 3,808 ms
コンパイル使用メモリ 74,968 KB
実行使用メモリ 41,808 KB
最終ジャッジ日時 2024-05-01 09:06:12
合計ジャッジ時間 8,908 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
41,268 KB
testcase_01 AC 131 ms
41,280 KB
testcase_02 AC 133 ms
41,408 KB
testcase_03 AC 130 ms
41,468 KB
testcase_04 AC 128 ms
41,220 KB
testcase_05 AC 118 ms
41,420 KB
testcase_06 AC 130 ms
41,280 KB
testcase_07 AC 126 ms
41,448 KB
testcase_08 AC 127 ms
41,100 KB
testcase_09 AC 122 ms
41,464 KB
testcase_10 AC 128 ms
41,764 KB
testcase_11 AC 127 ms
41,424 KB
testcase_12 AC 128 ms
41,152 KB
testcase_13 AC 126 ms
41,756 KB
testcase_14 AC 128 ms
41,148 KB
testcase_15 AC 131 ms
41,780 KB
testcase_16 AC 132 ms
41,172 KB
testcase_17 AC 131 ms
41,464 KB
testcase_18 AC 126 ms
41,472 KB
testcase_19 AC 122 ms
41,584 KB
testcase_20 AC 121 ms
41,808 KB
testcase_21 AC 118 ms
41,300 KB
testcase_22 AC 120 ms
41,460 KB
testcase_23 AC 121 ms
41,560 KB
testcase_24 AC 123 ms
41,412 KB
testcase_25 AC 122 ms
41,260 KB
testcase_26 AC 118 ms
41,512 KB
testcase_27 AC 130 ms
41,276 KB
testcase_28 AC 124 ms
41,300 KB
testcase_29 AC 129 ms
41,260 KB
testcase_30 AC 127 ms
41,600 KB
testcase_31 AC 126 ms
41,460 KB
testcase_32 AC 126 ms
41,148 KB
testcase_33 AC 124 ms
41,336 KB
testcase_34 AC 118 ms
41,248 KB
testcase_35 AC 125 ms
41,628 KB
testcase_36 AC 125 ms
41,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise58{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    long n = sc.nextInt();

    long a = sc.nextInt();
    long b = sc.nextInt();
    long c = sc.nextInt();

    long count = 0;

    count += n / a;
    count += n / b;
    count += n / c;

    long lcmAB = getLcm(b, a);
    count -= n / lcmAB;

    long lcmBC = getLcm(c, b);
    count -= n / lcmBC;

    long lcmAC = getLcm(c, a);
    count -= n / lcmAC;

    long lcmAll = getLcm(lcmBC, a);
    count += n / lcmAll;

    System.out.println(count);
    
  }
  private static long ea(long biggerNum, long smallerNum){
    long mod = biggerNum % smallerNum;
    if (mod == 0){
      return smallerNum;
    } else {
      return ea(smallerNum, mod);
    }
  }
  private static long getLcm(long biggerNum, long smallerNum){
    long gcm = ea(biggerNum, smallerNum);
    long lcm = biggerNum * smallerNum / gcm;
    return lcm;
  }
}
0