結果
| 問題 |
No.1276 3枚のカード
|
| コンテスト | |
| ユーザー |
logx
|
| 提出日時 | 2020-10-30 20:58:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 343 ms / 2,000 ms |
| コード長 | 2,545 bytes |
| コンパイル時間 | 1,712 ms |
| コンパイル使用メモリ | 169,020 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-21 23:03:07 |
| 合計ジャッジ時間 | 12,779 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 61 |
ソースコード
#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;}
constexpr pair<ll,ll> forinv(ll a,ll b)const noexcept{
if(b==0)return pair<ll,ll>(1,0);
pair<ll,ll> cnt1 = forinv(b,a%b);
pair<ll,ll> t=pair<ll,ll>(cnt1.second,cnt1.first-a/b*cnt1.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 cnt1=0;
ll rt=undersqrt(a);
rep(i,rt)cnt1+=a/(i+1);
return cnt1*2-rt*rt;
}
int main(){
ll n;cin >> n;
ll rt = undersqrt(n);
mint cnt1=0;
rep2(i,1,rt+1){
cnt1 += solve(n/i);
cnt1 += solve(i) * (n/i-n/(i+1));
}
if(rt * (rt+1) > n)cnt1 -= solve(rt);
cnt1 += -solve(n)*2 + n;
mint cnt2=0;
rep2(i,1,rt+1)cnt2 += (mint)(n/i-1)*(n/i-2) + (i-1)*(i-2)*(n/i-n/(i+1));
if(rt*(rt+1)>n)cnt2 -= (rt-1)*(rt-2);
cnt2 -= cnt1*2;
mint cnt3=0;
rep2(i,1,rt+1)cnt3 += (n - 2)*(n/i - 1) + (n-2) * (i-1) * (n/i - n/(i+1));
if(rt*(rt+1)>n)cnt3 -= (n-2) * (rt-1);
mint sum = cnt3 - cnt1*3 - cnt2;
cout << sum << endl;
assert(3LL<=n&&n<=2000000000LL);
}
logx