結果

問題 No.3535 $E\times - Otogibanashi$
コンテスト
ユーザー nauclhlt
提出日時 2026-03-31 15:52:45
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 992 ms / 2,000 ms
コード長 1,103 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,378 ms
コンパイル使用メモリ 221,552 KB
実行使用メモリ 91,868 KB
最終ジャッジ日時 2026-05-08 20:55:09
合計ジャッジ時間 12,977 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll N, P;
    cin >> N >> P;

    vector<ll> all;

    for (int a = 1; a <= 9; a++)
    {
        for (int b = 0; b <= 9; b++)
        {
            for (int c = 0; c <= 9; c++)
            {
                ll number = 110000 * a + 1001 * b + 110 * c;
                all.push_back(number);
            }
        }
    }

    sort(all.begin(), all.end());

    vector<ll> s;
    for (int i = 0; i < all.size(); i++)
    {
        bool ok = true;
        for (int j = 0; j < i; j++)
        {
            ok &= (all[i] % all[j] != 0);
        }

        if (ok)
        {
            s.push_back(all[i]);
        }
    }

    unordered_set<ll> seen;

    ll ans = 0LL;

    for (int i = 0; i < s.size(); i++)
    {
        for (ll n = s[i]; n <= N; n += s[i])
        {
            if (seen.count(n)) continue;
            seen.insert(n);

            ans += n;
            ans %= P;
        }
    }

    ans = P - ans;
    ans %= P;

    cout << ans << endl;
}
0