結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー koyumeishi
提出日時 2015-12-09 00:31:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 874 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 75,080 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-21 11:22:42
合計ジャッジ時間 1,664 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |         scanf("%lld", &n);
      |         ~~~~~^~~~~~~~~~~~
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         scanf("%lld%lld%lld", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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;
}



int main(){
	long long n;
	//cin >> n;
	scanf("%lld", &n);
	long long a,b,c;
	//cin >> a >> b >> c;
	scanf("%lld%lld%lld", &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;
	printf("%lld\n", ans);
	return 0;
}
0