結果

問題 No.1276 3枚のカード
ユーザー logxlogx
提出日時 2020-09-17 22:55:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 348 ms / 2,000 ms
コード長 3,090 bytes
コンパイル時間 1,608 ms
コンパイル使用メモリ 167,176 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 08:00:24
合計ジャッジ時間 14,044 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 294 ms
4,380 KB
testcase_11 AC 138 ms
4,380 KB
testcase_12 AC 176 ms
4,380 KB
testcase_13 AC 184 ms
4,380 KB
testcase_14 AC 18 ms
4,384 KB
testcase_15 AC 149 ms
4,380 KB
testcase_16 AC 320 ms
4,380 KB
testcase_17 AC 172 ms
4,380 KB
testcase_18 AC 130 ms
4,376 KB
testcase_19 AC 211 ms
4,380 KB
testcase_20 AC 123 ms
4,380 KB
testcase_21 AC 127 ms
4,376 KB
testcase_22 AC 323 ms
4,376 KB
testcase_23 AC 15 ms
4,380 KB
testcase_24 AC 201 ms
4,380 KB
testcase_25 AC 67 ms
4,380 KB
testcase_26 AC 247 ms
4,376 KB
testcase_27 AC 283 ms
4,380 KB
testcase_28 AC 274 ms
4,380 KB
testcase_29 AC 158 ms
4,384 KB
testcase_30 AC 31 ms
4,380 KB
testcase_31 AC 14 ms
4,376 KB
testcase_32 AC 72 ms
4,380 KB
testcase_33 AC 6 ms
4,380 KB
testcase_34 AC 50 ms
4,380 KB
testcase_35 AC 47 ms
4,380 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 44 ms
4,376 KB
testcase_38 AC 29 ms
4,380 KB
testcase_39 AC 76 ms
4,380 KB
testcase_40 AC 312 ms
4,384 KB
testcase_41 AC 256 ms
4,376 KB
testcase_42 AC 277 ms
4,380 KB
testcase_43 AC 241 ms
4,380 KB
testcase_44 AC 344 ms
4,376 KB
testcase_45 AC 311 ms
4,380 KB
testcase_46 AC 310 ms
4,380 KB
testcase_47 AC 256 ms
4,376 KB
testcase_48 AC 246 ms
4,380 KB
testcase_49 AC 279 ms
4,376 KB
testcase_50 AC 308 ms
4,384 KB
testcase_51 AC 264 ms
4,384 KB
testcase_52 AC 226 ms
4,376 KB
testcase_53 AC 266 ms
4,380 KB
testcase_54 AC 307 ms
4,384 KB
testcase_55 AC 236 ms
4,380 KB
testcase_56 AC 229 ms
4,376 KB
testcase_57 AC 293 ms
4,380 KB
testcase_58 AC 305 ms
4,376 KB
testcase_59 AC 267 ms
4,380 KB
testcase_60 AC 348 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;

template <ll mod> struct Fp{
    ll x;
    constexpr Fp(ll x=0) noexcept : x ((x%mod+mod)%mod){}
    /*-------ここから演算子-------*/
    constexpr Fp operator-() const noexcept{
        return Fp(-x);
    }
    constexpr Fp& operator+=(const Fp &a) noexcept{
        if((x+=a.x)>=mod)x-=mod;
        return *this;
    }
    constexpr Fp& operator-=(const Fp &a) noexcept{
        if((x+=mod-a.x)>=mod)x-=mod;
        return *this;
    }
    constexpr Fp& operator*=(const Fp &a) noexcept{
        (x*=a.x)%=mod;
        return *this;
    }
    constexpr Fp& operator/=(const Fp &a) noexcept{
        return (*this)*=a.inv();
    }
    constexpr Fp operator+(const Fp &a)const noexcept{
        Fp res(*this);
        return res+=a;
    }
    constexpr Fp operator-(const Fp &a)const noexcept{
        Fp res(*this);
        return res-=a;
    }
    constexpr Fp operator*(const Fp &a)const noexcept{
        Fp res(*this);
        return res*=a;
    }
    constexpr Fp operator/(const Fp &a)const noexcept{
        Fp res(*this);
        return res/=a;
    }
    /*-------ここまで演算子-------*/
    constexpr Fp inv()const noexcept{
        return (Fp)forinv((*this).x,mod).first;
    }

    friend ostream& operator<<(ostream &os,const Fp &m)noexcept{
        os << m.x;
        return os;
   }
    friend istream& operator>>(istream &is,Fp &m)noexcept{
        is >> m.x;
        m.x%=mod;
        if(m.x<0)m.x+=mod;
        return is;
    }

private:
    //Euclidの互除法
    constexpr pair<ll,ll> forinv(ll a,ll b)const noexcept{
        if(b==0)return pair<ll,ll>(1,0);

        pair<ll,ll> ans = forinv(b,a%b);
        pair<ll,ll> t=pair<ll,ll>(ans.second,ans.first-a/b*ans.second);
        return t;
    }
};
const ll mod=1000000007LL;
using mint=Fp<mod>;

ll undersqrt(ll a){//[sqrt(a)]を返す
    ll under=-1;
    ll over=a+1;
    while(over-under>1){
        ll mid=(under+over)/2;
        if(mid*mid<=a)under=mid;
        else over=mid;
    }
    return under;
}

mint solve(ll a){
    mint ans=0;
    ll tmp=undersqrt(a);
    for(ll i=1;i<=tmp;i++)ans+=a/i;
    return ans*2-tmp*tmp;
}

int main(){
    ll N;cin >> N;
    ll tmp = undersqrt(N);
    //ansはa|b,b|c型(a=2,b=4,c=12など)
    mint ans=0;
    for(int i=1;i<=tmp;i++){
        ans += solve(N/i);
        ans += solve(i) * ((N/i) - (N/(i+1)));
    }
    if(tmp * (tmp+1) > N){
        ans -= solve(tmp);
    }
    ans += -solve(N)*2 + N;

    mint count=0;
    for(int i=1;i<=tmp;i++){
        count += (mint)(N/i - 1)*(N/i - 2) + (i-1)*(i-2) * (N/i - N/(i+1));
    }
    if(tmp*(tmp+1)>N){
        count -= (tmp-1)*(tmp-2);
    }
    count -= ans*2;

    mint count2=0;
    for(int i=1;i<=tmp;i++)count2 += (N - 2)*(N/i - 1) + (N-2) * (i-1) * (N/i - N/(i+1));

    if(tmp*(tmp+1)>N)count2 -= (N-2) * (tmp-1);

    mint sum = count2 - ans*3 - count;
    cout << sum << endl;

    assert(3LL<=N&&N<=2000000000LL);
}
0