結果
| 問題 | No.546 オンリー・ワン | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-07-14 23:46:36 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 2,000 ms | 
| コード長 | 525 bytes | 
| コンパイル時間 | 663 ms | 
| コンパイル使用メモリ | 69,120 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-08 00:00:45 | 
| 合計ジャッジ時間 | 1,272 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
コンパイルメッセージ
main.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main()
      | ^~~~
            
            ソースコード
#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;
}
            
            
            
        