結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;


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

long long lcm(long long a, long long b){
	if(a<b) swap(a,b);
	if(b==1) return a;
	return a * (b/gcd(a,b));
}

//template<class T>
long long lcm(const vector<long long> v){
	if(v.size()==1) return v[0];
	long long ret = v[0];
	for(int i=1; i<v.size(); i++){
		ret = lcm(ret, v[i]);
	}
	return ret;
}


long long extgcd(long long a, long long b, long long &x, long long &y){
	long long d=a;
	if(b!=0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}


int main(){
	long long n;
	cin >> n;
	long long a,b,c;
	cin >> a >> b >> c;
	long long ans = n/a + n/b + n/c - n/lcm(a,b) - n/lcm(b,c) - n/lcm(c,a) + n/lcm({a,b,c});
	cout << ans << endl;
	return 0;
}
0