結果
| 問題 | No.546 オンリー・ワン | 
| コンテスト | |
| ユーザー |  gzlcp | 
| 提出日時 | 2017-07-14 23:14:15 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 2,000 ms | 
| コード長 | 1,062 bytes | 
| コンパイル時間 | 837 ms | 
| コンパイル使用メモリ | 87,772 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-07 23:31:32 | 
| 合計ジャッジ時間 | 1,411 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 7 | 
ソースコード
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#define REP(i, n) for(long long i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
#define INF (long long)1000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}
ll solve(vector<ll> c, int m, int n) {
	ll res = 0;
	for(ll i = 1; i < (1 << m); i++) {
		ll num = 0;
		for(ll j = i; j != 0; j >>= 1) num += j & 1;
		ll lcm = 1;
		for(ll j = 0; j < m; ++j) {
			if((i >> j) & 1) {
				lcm = lcm / gcd(lcm, c[j]) * c[j];
				if(lcm > n) break;
			}
		}
		if(num % 2 == 0) res -= n / lcm;
		else res += n / lcm;
	}
	return res;
}
int main() {
	int n, l, h;
	cin>>n>>l>>h;
	vector<ll> c(n);
	REP(i, n) cin>>c[i];
	ll res = 0;
	REP(i, n) {
		vector<ll> b;
		REP(j, n) {
			if(j == i) continue;
			else b.push_back(c[j]);
		}
		res += solve(c, n, h) - solve(b, n - 1, h);
		if(l > 1) res -= solve(c, n, l - 1) - solve(b, n - 1, l - 1);
	}
	cout<<res<<endl;
}
            
            
            
        