結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー Kutimoti_T
提出日時 2018-09-03 10:45:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 632 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 161,536 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-06 17:12:40
合計ジャッジ時間 2,812 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

i64 gcd(i64 a,i64 b){
  if(b == 0) return a;
  return gcd(b,a % b);
}

int main(){
  i64 n,m;
  cin >> n;
  m = 3;
  vector<i64> a(m);
  rep(i,0,m - 1) cin >> a[i];

  i64 res = 0;
  for(int i = 1;i < (1 << m);i++){
    i64 LCM = 1;
    for(int j = 0;j < m;j++){
      if(i & (1 << j)){
        LCM = LCM / gcd(LCM , a[j]) * a[j];
      }
      if(LCM > n) break;
    }
    if(__builtin_popcount(i) & 1) res += n / LCM;
    else res -= n / LCM;
  }
  cout << res << endl;
}
0