結果

問題 No.546 オンリー・ワン
ユーザー hiyokko2hiyokko2
提出日時 2017-07-30 12:59:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 1,305 ms
コンパイル使用メモリ 162,700 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 05:54:15
合計ジャッジ時間 1,967 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;

int gcd(int a, int b)
{
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b)
{
    return a / gcd(a, b) * b;
}

//L以上、H以下の整数のうちCで割り切れる数の個数を返す
int divNum(int L, int H, int C)
{
    return H/C - (L-1)/C;
}

int N, L, H;
int C[15];

signed main()
{
    cin >> N >> L >> H;
    REP(i,N) cin >> C[i];

    int ans = 0;
    REP(i,N) {
        //ans += divNum(L, H, C[i]);

        vector<int> CC;
        REP(j,N) if (i != j) CC.push_back(C[j]);

        REP(mask,1<<CC.size()) {
            int lc = C[i];
            int cnt = 0;
            REP(j,CC.size()) if (mask & (1 << j)) lc = lcm(lc, CC[j]), cnt++;

            if (cnt % 2 == 0) ans += divNum(L, H, lc);
            else ans -= divNum(L, H, lc);
        }
    }

    cout << ans << endl;
}
0