結果

問題 No.546 オンリー・ワン
ユーザー btkbtk
提出日時 2017-07-18 15:57:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,566 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 168,452 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 01:56:26
合計ジャッジ時間 1,907 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 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 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
LL gcd(LL a,LL b){
    return (b==0)?a:gcd(b,a%b);
}
LL lcm(LL a,LL b){
    return (a*b)/gcd(a,b);
}
#define POS(n,x) ((n>>x)&1)
LL calc(LL b,const vector<LL> c){
    int N=c.size();
    int M=1<<N;
    vector<LL> dp(M);
    REP(nobu,M-1){
        int bit=(M-1)-nobu;
        //cout<<bit<<" ";
        LL g=1;
        REP(i,N)if(POS(bit,i))g=lcm(c[i],g);
        //cout<<g<<endl;
        dp[bit]=b/g;
        int sup=nobu;
        int sub=(nobu-1)&sup;

        while(sub!=sup){
            //cout<<M-1-sub<<" ";cout.flush();
            dp[bit]-=dp[M-1-sub];
            sub=(sub-1)&sup;
        }//cout<<dp[bit]<<endl;
    }
    LL res=0;
    for(int i=1;i<M;i<<=1){
        res+=dp[i];
    }
    return res;
}
int main(){
    LL N,L,H;
    cin>>N>>L>>H;
    vector<LL> C(N);
    cin>>C;
    cout<<calc(H,C)-calc(L-1,C)<<endl;
    return 0;
}
0