結果
問題 | No.316 もっと刺激的なFizzBuzzをください |
ユーザー |
![]() |
提出日時 | 2016-06-04 17:10:36 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 134 ms / 1,000 ms |
コード長 | 964 bytes |
コンパイル時間 | 3,343 ms |
コンパイル使用メモリ | 74,948 KB |
実行使用メモリ | 41,532 KB |
最終ジャッジ日時 | 2024-11-21 12:20:38 |
合計ジャッジ時間 | 9,040 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
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;}}