結果

問題 No.864 四方演算
ユーザー TAISA_
提出日時 2019-08-16 21:45:41
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 2,016 bytes
コンパイル時間 1,451 ms
コンパイル使用メモリ 167,772 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 10:45:05
合計ジャッジ時間 2,484 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (ll i = 1; i * i <= k; i++) {
        if (k % i == 0) {
            ll j = k / i;
            ll s, t;
            if (i <= n + 1LL) {
                s = i - 1LL;
            } else {
                s = 2LL * n - i + 1LL;
            }
            if (j <= n + 1LL) {
                t = j - 1LL;
            } else {
                t = 2LL * n - j + 1LL;
            }
            if (2LL * n < i) {
                s = 0;
            }
            if (2LL * n < j) {
                t = 0;
            }
            if (i == j) {
                ans += s * t;
            } else {
                ans += s * t * 2LL;
            }
        }
    }
    cout << ans << endl;
}
0