QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734927#9612. 月亮的背面是粉红色的hos_lyric#84 1996ms542228kbC++146.3kb2024-11-11 16:02:312024-11-11 16:02:32

Judging History

你现在查看的是最新测评结果

  • [2024-11-11 16:02:32]
  • 评测
  • 测评结果:84
  • 用时:1996ms
  • 内存:542228kb
  • [2024-11-11 16:02:31]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 1000000007;
using Mint = ModInt<MO>;


constexpr int LIM_SIEVE = 100'000'000;
constexpr int LIM_SIEVE_PI = 6'000'000;
int lpf[LIM_SIEVE + 1];
int primesLen;
int primes[LIM_SIEVE_PI];
char moe[LIM_SIEVE + 1];
int fs[LIM_SIEVE];
void sieveInit(int N) {
  fill(lpf, lpf + (N + 1), 0);
  primesLen = 0;
}
void sieve(int N) {
#ifdef LOCAL
  sieveInit(N);
#endif
  moe[1] = 1;
  fs[1] = 1;
  for (int n = 2; n <= N; ++n) {
    if (lpf[n] == 0) {
      lpf[n] = n;
      moe[n] = -1;
      primes[primesLen++] = n;
      fs[n] = 2;
    }
    for (int i = 0; i < primesLen && primes[i] <= lpf[n] && primes[i] * n <= N; ++i) {
      const int p = primes[i];
      const int nn = p * n;
      lpf[nn] = p;
      if (p == lpf[n]) {
        moe[nn] = 0;
        int e = 1;
        int m = n;
        do { ++e; m /= p; } while (m % p == 0);
        fs[nn] = (e + 1) * fs[m];
      } else {
        moe[nn] = -moe[n];
        fs[nn] = 2 * fs[n];
      }
    }
  }
}

Int gs[32'000'000];


__int128 s1(Int n) {
  return (__int128)n * (n + 1) / 2;
}

int main() {
  Int N;
  int M;
  for (; ~scanf("%lld%d", &N, &M); ) {
    const int sqrtN = sqrtl(N);
    sieve(sqrtN);
cerr<<"fs = ";pv(fs,fs+31);
    
    Mint ans[2] = {};
    {
      for (int n = 1; n <= sqrtN; ++n) fs[n] += fs[n - 1];
cerr<<COLOR("95")<<__LINE__<<": "<<clock()<<COLOR()<<endl;
      for (int a = 1; a <= sqrtN; ++a) if (moe[a]) {
        const Int n = N / ((Int)a * a);
        Int sum;
        if (n <= sqrtN) {
          sum = fs[n];
        } else {
          sum = 0;
          const int sn = sqrtl(n);
          for (int i = 1; i <= sn; ++i) sum += n / i;
          sum *= 2;
          sum -= (Int)sn * sn;
        }
        ans[0] += moe[a] * sum;
      }
cerr<<COLOR("95")<<__LINE__<<": "<<clock()<<COLOR()<<endl;
    }
    if (M) {
      for (int n = 1; n <= sqrtN; ++n) gs[n] = gs[n - 1] + (Int)n * (fs[n] - fs[n - 1]);
cerr<<COLOR("95")<<__LINE__<<": "<<clock()<<COLOR()<<endl;
      for (int a = 1; a <= sqrtN; ++a) if (moe[a]) {
        const Int n = N / ((Int)a * a);
        __int128 sum;
        if (n <= sqrtN) {
          sum = gs[n];
        } else {
          sum = 0;
          const int sn = sqrtl(n);
          for (int i = 1; i <= sn; ++i) sum += i * s1(n / i);
          sum *= 2;
          sum -= s1(sn) * s1(sn);
        }
        ans[1] += moe[a] * Mint(a) * Mint(a) * (unsigned)(sum % MO);
      }
cerr<<COLOR("95")<<__LINE__<<": "<<clock()<<COLOR()<<endl;
    }
    
    ans[0] *= ans[0];
    ans[1] *= ans[1];
    printf("%u", ans[0].x);
    if (M) printf(" %u", ans[1].x);
    puts("");
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 2ms
memory: 10064kb

input:

1726 1

output:

84290761 74619067

result:

ok 2 number(s): "84290761 74619067"

Test #2:

score: 3
Accepted
time: 0ms
memory: 10284kb

input:

3608 1

output:

433014481 672891299

result:

ok 2 number(s): "433014481 672891299"

Test #3:

score: 3
Accepted
time: 1ms
memory: 10000kb

input:

2921 1

output:

271096225 547734266

result:

ok 2 number(s): "271096225 547734266"

Subtask #2:

score: 3
Accepted

Test #4:

score: 3
Accepted
time: 0ms
memory: 10004kb

input:

6116899 1

output:

219318963 301450440

result:

ok 2 number(s): "219318963 301450440"

Test #5:

score: 3
Accepted
time: 1ms
memory: 10060kb

input:

6260707 1

output:

148720176 263856753

result:

ok 2 number(s): "148720176 263856753"

Test #6:

score: 3
Accepted
time: 2ms
memory: 12220kb

input:

6763677 1

output:

944542490 136397156

result:

ok 2 number(s): "944542490 136397156"

Subtask #3:

score: 8
Accepted

Test #7:

score: 8
Accepted
time: 0ms
memory: 12328kb

input:

6469467712 0

output:

147393348

result:

ok 1 number(s): "147393348"

Test #8:

score: 8
Accepted
time: 0ms
memory: 10592kb

input:

8967004453 0

output:

229436583

result:

ok 1 number(s): "229436583"

Test #9:

score: 8
Accepted
time: 4ms
memory: 12520kb

input:

6636594384 0

output:

995965072

result:

ok 1 number(s): "995965072"

Subtask #4:

score: 8
Accepted

Test #10:

score: 8
Accepted
time: 0ms
memory: 11280kb

input:

8292948816 1

output:

566765721 287485757

result:

ok 2 number(s): "566765721 287485757"

Test #11:

score: 8
Accepted
time: 6ms
memory: 13048kb

input:

8592748771 1

output:

649470692 164561252

result:

ok 2 number(s): "649470692 164561252"

Test #12:

score: 8
Accepted
time: 6ms
memory: 11132kb

input:

9827380808 1

output:

291159931 188690805

result:

ok 2 number(s): "291159931 188690805"

Subtask #5:

score: 8
Accepted

Test #13:

score: 8
Accepted
time: 46ms
memory: 31020kb

input:

900472451132 1

output:

247050500 963765719

result:

ok 2 number(s): "247050500 963765719"

Test #14:

score: 8
Accepted
time: 50ms
memory: 27900kb

input:

850862494659 1

output:

200210720 915108650

result:

ok 2 number(s): "200210720 915108650"

Test #15:

score: 8
Accepted
time: 44ms
memory: 28848kb

input:

851346512859 1

output:

895785763 504512885

result:

ok 2 number(s): "895785763 504512885"

Subtask #6:

score: 10
Accepted

Test #16:

score: 10
Accepted
time: 182ms
memory: 63448kb

input:

9864907300784 1

output:

359943536 720268421

result:

ok 2 number(s): "359943536 720268421"

Test #17:

score: 10
Accepted
time: 204ms
memory: 59452kb

input:

8181674676063 1

output:

839993102 994056029

result:

ok 2 number(s): "839993102 994056029"

Test #18:

score: 10
Accepted
time: 173ms
memory: 65380kb

input:

9893510217522 1

output:

157499971 930653488

result:

ok 2 number(s): "157499971 930653488"

Subtask #7:

score: 13
Accepted

Test #19:

score: 13
Accepted
time: 308ms
memory: 100764kb

input:

96735749745529 0

output:

223354886

result:

ok 1 number(s): "223354886"

Test #20:

score: 13
Accepted
time: 306ms
memory: 98248kb

input:

95243570720799 0

output:

555372474

result:

ok 1 number(s): "555372474"

Test #21:

score: 13
Accepted
time: 316ms
memory: 100508kb

input:

97668723090105 0

output:

84562124

result:

ok 1 number(s): "84562124"

Subtask #8:

score: 14
Accepted

Test #22:

score: 14
Accepted
time: 573ms
memory: 174784kb

input:

94060593399194 1

output:

52991150 887133157

result:

ok 2 number(s): "52991150 887133157"

Test #23:

score: 14
Accepted
time: 606ms
memory: 180708kb

input:

98527940728119 1

output:

281611635 910356955

result:

ok 2 number(s): "281611635 910356955"

Test #24:

score: 14
Accepted
time: 566ms
memory: 172136kb

input:

90501814019947 1

output:

666385143 229785369

result:

ok 2 number(s): "666385143 229785369"

Subtask #9:

score: 0
Time Limit Exceeded

Test #25:

score: 0
Time Limit Exceeded

input:

9772457586483846 0

output:


result:


Subtask #10:

score: 17
Accepted

Test #31:

score: 17
Accepted
time: 1925ms
memory: 530088kb

input:

949243849085176 1

output:

508465534 771553755

result:

ok 2 number(s): "508465534 771553755"

Test #32:

score: 17
Accepted
time: 1880ms
memory: 523632kb

input:

924225524519163 1

output:

867410272 870831653

result:

ok 2 number(s): "867410272 870831653"

Test #33:

score: 17
Accepted
time: 1953ms
memory: 537108kb

input:

978079151303393 1

output:

235076358 675828942

result:

ok 2 number(s): "235076358 675828942"

Test #34:

score: 17
Accepted
time: 1893ms
memory: 523620kb

input:

929804617107620 1

output:

790604296 73162158

result:

ok 2 number(s): "790604296 73162158"

Test #35:

score: 17
Accepted
time: 1996ms
memory: 542228kb

input:

989806727450552 1

output:

378550840 783149232

result:

ok 2 number(s): "378550840 783149232"