結果

問題 No.1627 三角形の成立
ユーザー milanis48663220milanis48663220
提出日時 2023-08-07 23:46:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 1,000 ms
コード長 2,103 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 123,080 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 17:57:20
合計ジャッジ時間 2,549 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 64 ms
6,940 KB
testcase_06 AC 42 ms
6,940 KB
testcase_07 AC 10 ms
6,940 KB
testcase_08 AC 53 ms
6,940 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 20 ms
6,940 KB
testcase_11 AC 14 ms
6,940 KB
testcase_12 AC 27 ms
6,944 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 43 ms
6,940 KB
testcase_15 AC 23 ms
6,944 KB
testcase_16 AC 7 ms
6,944 KB
testcase_17 AC 20 ms
6,940 KB
testcase_18 AC 43 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint1000000007;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

mint comb3(mint n){
    mint ans = n*(n-1)*(n-2)/6;
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    if(n > m) swap(n, m);
    vector<mint> sum(n+1);
    for(int g = 1; g <= n; g++){
        int xl = g, xr = (n/g)*g;
        int yl = g, yr = (m/g)*g;
        mint sum_x = (mint(n-xl)+mint(n-xr))*(n/g)/2;
        mint sum_y = (mint(m-yl)+mint(m-yr))*(m/g)/2;
        sum[g] = sum_x*sum_y;
    }
    mint ans = comb3(mint(n)*mint(m));
    for(int g = n; g >= 1; g--){
        for(int i = 2; i*g <= n; i++){
            sum[g] -= sum[g*i];
        }
        ans -= sum[g]*(g-1)*2;
    }
    ans -= comb3(mint(n))*m;
    ans -= comb3(mint(m))*n;
    cout << ans << endl;
}
0