結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー k
提出日時 2020-08-15 05:47:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 774 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 192,984 KB
最終ジャッジ日時 2025-01-13 01:02:49
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

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

// override function template of std::gcd
long long gcd(int a, int b) {
  return gcd((long long)a, (long long)b);
}

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

// override function template of std::lcm
long long lcm(int a, int b) {
  return lcm((long long)a, (long long)b);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  long long n;
  int a, b, c;
  cin >> n >> a >> b >> c;

  long long ret = n/a + n/b + n/c;
  ret -= n/lcm(a,b) + n/lcm(b,c) + n/lcm(c,a);
  ret += n/lcm(lcm(a,b), c);
  
  cout << ret << endl;
  
  return 0;
}
0