結果

問題 No.546 オンリー・ワン
ユーザー hashiryohashiryo
提出日時 2018-04-22 19:27:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 63,148 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 14:07:51
合計ジャッジ時間 1,681 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//


#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

typedef long long ll;

int N;
ll L, H;
ll C[11];
ll ans;

ll gcd(ll x,ll y){
    return y==0? x:gcd(y,x%y);
}

ll lcm(ll x,ll y){
    return x*y/gcd(x,y);
}

ll lcmC[1<<11];

ll solve(int d,int num,int s){
    int e = num&1? 1:-1;
    if(d == N)
        return e*num*(H/lcmC[s]-(L-1)/lcmC[s]);
    ll res=0;
    res += solve(d+1,num,s);
    res += solve(d+1,num+1,s|(1<<d));
    return res;
}

int main() {
    // insert code here...    return 0;
  //////
    // input from txt
    /*
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    std::ofstream out("output.txt");
    std::cout.rdbuf(out.rdbuf());
   ///////
     */
    cin >> N >> L >> H;
    for(int i=0;i<N;i++){
        cin >> C[i];
    }
    
    int total = 1 << N;
    lcmC[0] = 1;
    for(int s = 0;s < total;s++){
        for(int u=0;u<N;u++){
            lcmC[s|(1<<u)] = lcm(lcmC[s],C[u]);
        }
    }
    ans = solve(0,0,0);
    cout << ans << endl;
    
    return 0;
}
0