結果

問題 No.864 四方演算
ユーザー TomysLaboTomysLabo
提出日時 2023-05-20 13:34:44
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,451 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 93,948 KB
実行使用メモリ 7,632 KB
最終ジャッジ日時 2023-08-23 09:28:51
合計ジャッジ時間 5,313 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << vec[0];
    for (int i = 1; i < (int)vec.size(); i++) os << " " << vec[i];
    return os;
}
template<typename T> istream& operator>>(istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

vector<ll> getDivisions(ll N) {
    vector<ll> ans;
    ll i = 1;
    for (i = 1; i * i < N; i++) {
        if (N % i == 0) {
            ans.push_back(i);
            ans.push_back(N / i);
        }
    }
    if (i * i == N) ans.push_back(i);
    return ans;
}

// (a + c) * (b + d) = K
int main() {
    ll N, K; cin >> N >> K;
    vector<ll> divisions = getDivisions(K);

    ll ans = 0;
    for (auto div : divisions) {
        int cnt1 = 0;
        for (int a = 1; a <= div; a++) {
            if (a <= N && div - a <= N && div - a >= 1) cnt1++;
        }
        int cnt2 = 0;
        for (int c = 1; c <= K / div; c++) {
            if (c <= N && K / div - c <= N && K / div - c >= 1) cnt2++;
        }
        ans += (ll)cnt1 * cnt2;
    }

    cout << ans << endl;
    return 0;
}

0