結果
問題 | No.316 もっと刺激的なFizzBuzzをください |
ユーザー |
|
提出日時 | 2016-05-18 18:28:30 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 135 ms / 1,000 ms |
コード長 | 710 bytes |
コンパイル時間 | 2,129 ms |
コンパイル使用メモリ | 74,220 KB |
実行使用メモリ | 41,648 KB |
最終ジャッジ日時 | 2024-11-21 12:20:13 |
合計ジャッジ時間 | 8,077 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
import java.util.Scanner;public class Main{public static void main(String[] args){new Main().solve();}void solve(){Scanner sc=new Scanner(System.in);long n=sc.nextLong();long a=sc.nextLong();long b=sc.nextLong();long c=sc.nextLong();/*** 1<=x<=Nの範囲でa,b,cのいずれかの倍数となるものの個数を数える。**/long ans=n/a+n/b+n/c-n/lcm(a,b)-n/lcm(b,c)-n/lcm(c,a)+n/lcm(lcm(a,b),c);System.out.println(ans);}long lcm(long t1,long t2){long a=gcd(t1,t2);long tt1=t1/a;long tt2=t2/a;return tt1*tt2*a;}long gcd(long t1,long t2){if(t1<t2){long d=t2;t2=t1;t1=d;}if(t2==0)return t1;return gcd(t2,t1%t2);}}