結果
問題 | No.546 オンリー・ワン |
ユーザー |
![]() |
提出日時 | 2018-05-31 14:45:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 822 bytes |
コンパイル時間 | 1,656 ms |
コンパイル使用メモリ | 173,448 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-30 08:31:38 |
合計ジャッジ時間 | 2,331 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
コンパイルメッセージ
main.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 17 | main(){ | ^~~~
ソースコード
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int INF = (1LL << 30) - 1; int MOD = 1e9+7; ll gcd (ll a,ll b){ return b ? gcd(b,a%b) : a; } ll lcm(vector<ll> V){ ll l = V[0]; for(auto i:V){ l = l / gcd(l,i) * i; } return l; } main(){ ll N,L,H; cin >> N >> L >> H; vector<ll> C(N); rep(i,N)cin >> C[i]; ll ans = 0; rep(i,1 << N){ if(!i)continue; int bit = __builtin_popcountll(i); vector<ll> V; rep(j,N){ if(i & (1 << j)){ V.push_back(C[j]); } } auto l = lcm(V); ll cnt = H / l - (L-1) / l; //cout << cnt << endl; ans += (bit&1 ? cnt * bit : -cnt * bit); } cout << ans << endl; }