結果

問題 No.826 連絡網
ユーザー coco18000coco18000
提出日時 2019-05-03 22:07:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,342 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 167,668 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 06:09:38
合計ジャッジ時間 5,230 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

bool U[1000005];

int main()
{
    ll N, P;
    cin >> N >> P;

    ll ans = 1;
    vector<ll> prime;
    for (int i = 2; i <= N; ++i)
    {
        if (U[i])
            continue;
        prime.push_back(i);
        for (int j = i; j <= N; j += i)
            U[j] = true;
    }

    vector<ll> p;
    REP(i, prime.size())
    {
        if (P % prime[i] == 0)
            p.push_back(prime[i]);
    }
    if (p.size() > 0)
    {
        ll mp = p[0];
        REP(i, prime.size())
        {
            if (prime[i] * mp <= N)
            {
                p.push_back(prime[i]);
                mp = std::min(mp, prime[i]);
            }
        }
    }
    //sort(p.begin(), p.end());
    //p.erase(unique(p.begin(), p.end()), p.end());
    FOR(i, N + 1, 1)
    {
        if (i == P)
            continue;
        bool e = false;
        REP(j, p.size())
        {
            if (i % p[j] == 0)
            {
                e = true;
                break;
            }
        }
        if (e)
            ans++;
    }
    cout << ans << endl;
    return 0;
}
0