結果
問題 | No.316 もっと刺激的なFizzBuzzをください |
ユーザー |
![]() |
提出日時 | 2020-03-15 13:54:33 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 125 ms / 1,000 ms |
コード長 | 1,538 bytes |
コンパイル時間 | 4,363 ms |
コンパイル使用メモリ | 76,952 KB |
実行使用メモリ | 54,328 KB |
最終ジャッジ日時 | 2024-11-24 23:05:26 |
合計ジャッジ時間 | 8,148 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
import java.io.OutputStream;import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import java.util.Scanner;/*** Built using CHelper plug-in* Actual solution is at the top** @author silviase*/public class Main {public static void main(String[] args) {InputStream inputStream = System.in;OutputStream outputStream = System.out;Scanner in = new Scanner(inputStream);PrintWriter out = new PrintWriter(outputStream);MoreFizzBuzz solver = new MoreFizzBuzz();solver.solve(1, in, out);out.close();}static class MoreFizzBuzz {public void solve(int testNumber, Scanner in, PrintWriter out) {// 包徐原理を用いればいい// -a-b-c+(ab)+(bc)+(ca)-(abc)long n = in.nextLong();long a = in.nextLong();long b = in.nextLong();long c = in.nextLong();long res =+(n / a) + (n / b) + (n / c)- (n / Arith.lcm(a, b))- (n / Arith.lcm(b, c))- (n / Arith.lcm(c, a))+ (n / Arith.lcm(Arith.lcm(a, b), c));out.println(res);}}static class Arith {public static long gcd(long a, long b) {return a % b == 0 ? b : gcd(b, a % b);}public static long lcm(long a, long b) {return a / gcd(a, b) * b;}}}