結果

問題 No.2705 L to R Graph (Another ver.)
ユーザー maksimmaksim
提出日時 2024-03-29 23:13:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,875 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 168,300 KB
実行使用メモリ 9,876 KB
最終ジャッジ日時 2024-03-29 23:13:39
合計ジャッジ時間 6,610 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 TLE -
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 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define app push_back
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)
#else
#define debug(...)
#endif
#ifdef LOCAL
#define __int128 long long
#endif // LOCAL
const int inf=1e18;
int p;
int po(int a,int b) {if(b==0) {return 1;} if(b==1) {return a;} if(b%2==0) {int u=po(a,b/2);return (u*u)%p;} else {int u=po(a,b-1);return (a*u)%p;}}
int inv(int x) {return po(x,p-2);}
const int maxn=1e5+5;
int arr[maxn];int f[maxn];
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n>>p;
    for(int i=0;i<=n;++i)
    {
        for(int l=1;l<=n;++l)
        {
            for(int r=l;r<=n;++r)
            {
                int k=i/l;
                if(k*r>=i)
                {
                    f[i]++;
                }
            }
        }
    }
    int invn=inv(n);
    int cur=1;for(int i=0;i<n-1;++i) {cur*=n;cur%=p;}
    arr[0]=cur;
    for(int i=0;i<n-1;++i)
    {
        cur*=invn;cur%=p;cur*=(n-i-1);cur%=p;
        arr[i+1]=cur;
    }
    for(int i=n-1;i>=0;--i) {arr[i]+=arr[i+1];arr[i]%=p;}
    int res=0;
    for(int len=1;len<=n;++len)
    {
        int ways=arr[len-1];
        for(int l=1;l<=n;++l)
        {
            for(int r=l+1;r<=n;++r)
            {
                res+=len*ways;res%=p;
            }
        }
        for(int l=1;l<=n;++l)
        {
            res+=(len/__gcd(l,len))*ways;res%=p;
        }
    }
    for(int i=0;i<n;++i) {arr[i]=arr[i+1];}
    for(int i=n-1;i>=0;--i) {arr[i]+=arr[i+1];arr[i]%=p;}
    for(int i=0;i<=n-1;++i)
    {
        int ways=arr[i];
        res+=f[i]*ways;res%=p;
    }
    int c=1;for(int i=0;i<n;++i) {c*=n;c%=p;} c*=((n*(n+1)/2)%p);c%=p;
    res-=c;
    cout<<((n*res)%p+p)%p;
    return 0;
}
0