結果
問題 | No.316 もっと刺激的なFizzBuzzをください |
ユーザー |
![]() |
提出日時 | 2015-12-09 03:09:03 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 142 ms / 1,000 ms |
コード長 | 687 bytes |
コンパイル時間 | 2,749 ms |
コンパイル使用メモリ | 74,408 KB |
実行使用メモリ | 54,396 KB |
最終ジャッジ日時 | 2024-11-21 11:28:02 |
合計ジャッジ時間 | 9,281 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
package no316;import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);long n = sc.nextLong();long[] a = new long[3];for(int i=0;i<3;i++) {a[i] = sc.nextLong();}long count = 0;for(int i=1;i<8;i++) {long lcm = 1;for(int j=0;j<3;j++) {if ((i>>j&1)>0) {lcm = lcm(lcm,a[j]);}}count += (n / lcm) * (Integer.bitCount(i) % 2 == 1 ? 1 : -1);}System.out.println(count);}public static long gcd(long a,long b) {while(b!=0) {long r = a%b;a = b;b = r;}return a;}public static long lcm(long a,long b) {return a / gcd(a,b) * b;}}