結果

問題 No.864 四方演算
ユーザー mine691
提出日時 2019-08-16 22:22:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,037 bytes
コンパイル時間 1,742 ms
コンパイル使用メモリ 173,600 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-24 18:04:13
合計ジャッジ時間 2,724 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll ans = 0, N, K;

template <typename T>
vector<T> divisor(T n)
{
    vector<T> divisor;
    for (T i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            divisor.push_back(i);
            if (i * i != n)
                divisor.push_back(n / i);
        }
    }
    sort(divisor.begin(), divisor.end());
    return divisor;
}

int main()
{
    cin >> N >> K;

    auto d = divisor(K);

    for (int i = 0; i < d.size(); i++)
    {
        ll ac, bd;
        if (d[i] <= N)
            ac = max(d[i] - 1LL, 0LL);
        else if (2 * N <= d[i])
            ac = 0;
        else
            ac = 2 * N - (d[i] - 1LL);

        if (K / d[i] <= N)
            bd = max(K / d[i] - 1LL, 0LL);
        else if (2 * N <= K / d[i])
            bd = 0;
        else
            bd = 2 * N - (K / d[i] - 1LL);
        ans += ac * bd;
    }

    cout << ans << endl;
}
0