結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー knk
提出日時 2017-09-18 13:37:28
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 573 bytes
コンパイル時間 771 ms
コンパイル使用メモリ 68,992 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 02:29:06
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>

typedef long long ll;

ll gcd(ll a, ll b)
{
  while (a%b!=0 && b%a!=0) {
    if (a>b) a%=b;
    else b%=a;
  }
  return std::min(a, b);
}

inline ll lcm(ll a, ll b)
{
  return a/gcd(a, b)*b;
}

int main(void)
{
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(8);
  ll n, a, b, c;
  std::cin >> n >> a >> b >> c;
  ll ans = 0;
  ans += n/a + n/b + n/c;
  ans -= n/lcm(a, b) + n/lcm(b, c) + n/lcm(c, a);
  ans += n/lcm(a, lcm(b, c));
  std::cout << ans << std::endl;
  return 0;
}
0