結果

問題 No.1260 たくさんの多項式
ユーザー beetbeet
提出日時 2020-10-24 13:52:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 3,131 bytes
コンパイル時間 4,082 ms
コンパイル使用メモリ 203,336 KB
実行使用メモリ 37,360 KB
最終ジャッジ日時 2023-09-28 20:24:24
合計ジャッジ時間 14,801 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 293 ms
36,184 KB
testcase_21 AC 90 ms
20,224 KB
testcase_22 AC 257 ms
36,536 KB
testcase_23 AC 213 ms
36,292 KB
testcase_24 AC 219 ms
36,284 KB
testcase_25 AC 178 ms
37,152 KB
testcase_26 AC 208 ms
35,968 KB
testcase_27 AC 169 ms
36,232 KB
testcase_28 AC 287 ms
36,920 KB
testcase_29 AC 216 ms
36,596 KB
testcase_30 AC 137 ms
20,592 KB
testcase_31 AC 218 ms
36,340 KB
testcase_32 AC 217 ms
36,772 KB
testcase_33 AC 181 ms
36,936 KB
testcase_34 AC 276 ms
36,820 KB
testcase_35 AC 127 ms
20,360 KB
testcase_36 AC 117 ms
20,328 KB
testcase_37 AC 222 ms
36,552 KB
testcase_38 AC 236 ms
36,172 KB
testcase_39 AC 283 ms
36,544 KB
testcase_40 AC 216 ms
35,980 KB
testcase_41 AC 265 ms
37,272 KB
testcase_42 AC 202 ms
37,360 KB
testcase_43 AC 273 ms
36,012 KB
testcase_44 AC 184 ms
36,304 KB
testcase_45 AC 177 ms
36,476 KB
testcase_46 AC 157 ms
20,236 KB
testcase_47 AC 199 ms
36,940 KB
testcase_48 AC 45 ms
12,964 KB
testcase_49 AC 148 ms
20,800 KB
testcase_50 AC 79 ms
11,520 KB
testcase_51 AC 279 ms
36,108 KB
testcase_52 AC 100 ms
20,136 KB
testcase_53 AC 129 ms
19,752 KB
testcase_54 AC 288 ms
36,128 KB
testcase_55 AC 297 ms
36,596 KB
testcase_56 AC 140 ms
19,824 KB
testcase_57 AC 206 ms
36,108 KB
testcase_58 AC 128 ms
20,380 KB
testcase_59 AC 217 ms
36,924 KB
testcase_60 AC 297 ms
36,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// verification-helper: PROBLEM https://yukicoder.me/problems/5011

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
// split [1, n] into ranges whose elements have same quotients
template<typename T>
decltype(auto) quotients(T n){
  vector<pair<T, T>> vp;
  T m;
  for(m=1;m*m<=n;m++) vp.emplace_back(m,m);
  for(T i=m;i>=1;i--){
    T l=n/(i+1)+1,r=n/i;
    if(l<=r and vp.back().second<l)
      vp.emplace_back(l,r);
  }
  return vp;
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
  return 0;
}
#endif


#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;
#endif

//BEGIN CUT HERE
template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
//END CUT HERE
#ifndef call_from_test

//INSERT ABOVE HERE
signed ABC127_E(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int h,w,k;
  cin>>h>>w>>k;
  using M = Mint<int>;

  M ans{0};
  for(int d=1;d<h;d++)
    ans+=M(d)*M(h-d)*M(w)*M(w);

  for(int d=1;d<w;d++)
    ans+=M(d)*M(w-d)*M(h)*M(h);

  ans*=M::comb(h*w-2,k-2);
  cout<<ans<<endl;
  return 0;
}
/*
  verified on 2019/06/12
  https://atcoder.jp/contests/abc127/tasks/abc127_e
*/

signed main(){
  //ABC127_E();
  return 0;
}
#endif

#undef call_from_test

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  const char newl = '\n';
  using ll = long long;

  ll n;
  cin>>n;

  using M = Mint<int>;
  M ans{0};

  for(auto[l,r]:quotients(n)){
    if(l==1) continue;

    ll d=n/l;
    if(d<l){
      ans+=M(n)*M(r-l+1);
      ans-=M(d)*M(l-1+r-1)*M(r-l+1)/M(2);
      continue;
    }

    for(ll i=l;i<=r;i++)
      for(ll t=n;t;t/=i) ans+=M(t%i);
  }
  cout<<ans<<newl;
  return 0;
}
0