結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー legosuke
提出日時 2018-01-29 23:06:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 604 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 159,620 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 18:18:06
合計ジャッジ時間 2,890 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n;
  ll x[3];
  cin >> n;
  for (int i = 0; i < 3; i++) {
    cin >> x[i];
  }

  ll ans = 0;
  for (int i = 1; i < 1 << 3; i++) {
    ll lcm = 1;
    for (int j = 0; j < 3; j++) {
      if (!(i >> j & 1)) continue;
      lcm = lcm / gcd(lcm, x[j]) * x[j];
      if (lcm > n) break;
    }
    int sgn = __builtin_popcount(i) & 1 ? 1 : -1;
    ans += sgn * n / lcm;
  }
  cout << ans << endl;

  return 0;
}
0