結果

問題 No.546 オンリー・ワン
ユーザー kotatsugamekotatsugame
提出日時 2017-07-14 23:46:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 69,592 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 20:44:56
合計ジャッジ時間 1,213 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long gcd(long a,long b)
{
	return b?gcd(b,a%b):a;
}
long lcm(long a,long b)
{
	return a*b/gcd(a,b);
}
long n,l,h,c[10],ans;
void dfs(int i,long now,long cnt,long p,long pre)
{
	if(cnt==0)
	{
		ans+=(h/now-l/now)*pre*p;
		return;
	}
	else if(i==n)return;
	dfs(i+1,lcm(now,c[i]),cnt-1,p,pre);
	dfs(i+1,now,cnt,p,pre);
}
main()
{
	cin>>n>>l>>h;l--;
	for(int i=0;i<n;i++)cin>>c[i];
	for(int i=0;i++<n;)
	{
		dfs(0,1,i,i%2*2-1,i);
	}
	cout<<ans<<endl;
}
0