QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#418507#2586. 旧试题hos_lyric100 ✓479ms5720kbC++145.7kb2024-05-23 14:17:262024-05-23 14:17:27

Judging History

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

  • [2024-05-23 14:17:27]
  • 评测
  • 测评结果:100
  • 用时:479ms
  • 内存:5720kb
  • [2024-05-23 14:17:26]
  • 提交

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>;


/*
  (p^e0, p^e1, p^e2) -> e0+e1+e2+1
  \sum[e0,e1,e2>=0] (e0+e1+e2+1) x0^e0 x1^e1 x2^e2
  = x0/(1-x0)^2(1-x1)(1-x2) + x1/(1-x0)(1-x1)^2(1-x2) + x2/(1-x0)(1-x1)(1-x2)^2 + 1/(1-x0)(1-x1)(1-x2)
  = 1/(1-x0)^2(1-x1)^2(1-x2)^2 (1 - x0x1 - x0x2 - x1x2 + 2x0x1x2)
*/

int A, B, C;
int N;
vector<int> lpf, primes;

vector<Mint> wtsA, wtsB, wtsC;
Int counter;
Mint ans;

void dfs(int i, int a, int b, int c, Mint t) {
++counter;
  ans += t * wtsA[a] * wtsB[b] * wtsC[c];
  for (; ++i < (int)primes.size(); ) {
    const Int p = primes[i];
    const Int aa = a * p, bb = b * p, cc = c * p;
    if ((aa > A) + (bb > B) + (cc > C) >= 2) break;
    if (aa <= A && bb <= B) dfs(i, aa, bb, c, -t);
    if (aa <= A && cc <= C) dfs(i, aa, b, cc, -t);
    if (bb <= B && cc <= C) dfs(i, a, bb, cc, -t);
    if (aa <= A && bb <= B && cc <= C) dfs(i, aa, bb, cc, t + t);
  }
}

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d%d", &A, &B, &C);
    
    N = max({A, B, C});
    lpf.assign(N + 1, 0);
    primes.clear();
    for (int p = 2; p <= N; ++p) lpf[p] = p;
    for (int p = 2; p <= N; ++p) if (lpf[p] == p) {
      primes.push_back(p);
      for (int n = p; n <= N; n += p) chmin(lpf[n], p);
    }
    
    vector<int> Sigma0(N + 1, 0);
    for (int d = 1; d <= N; ++d) for (int n = d; n <= N; n += d) ++Sigma0[n];
    for (int n = 1; n <= N; ++n) Sigma0[n] += Sigma0[n - 1];
    wtsA.resize(A + 1);
    wtsB.resize(B + 1);
    wtsC.resize(C + 1);
    for (int n = 1; n <= A; ++n) wtsA[n] = Sigma0[A / n];
    for (int n = 1; n <= B; ++n) wtsB[n] = Sigma0[B / n];
    for (int n = 1; n <= C; ++n) wtsC[n] = Sigma0[C / n];
    
counter=0;
    ans = 0;
    dfs(-1, 1, 1, 1, 1);
cerr<<"A = "<<A<<", B = "<<B<<", C = "<<C<<": counter = "<<counter<<endl;
    printf("%u\n", ans.x);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

详细

Test #1:

score: 10
Accepted
time: 12ms
memory: 4076kb

input:

10
2619 2775 2558
2941 2738 2253
2523 2234 2814
2095 2001 2450
2074 2843 2478
2853 2891 2781
2096 2322 2484
2844 2285 2224
2019 2059 2676
2141 2850 2817

output:

427265215
845145293
265815811
249115533
183034505
150848053
247869267
904260863
862484831
861301172

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 17ms
memory: 3860kb

input:

10
3165 3578 3911
3592 3274 3353
3376 3782 3089
3709 3770 3246
3089 3897 3031
3103 3125 3574
3250 3833 3284
3488 3815 3324
3946 3982 3416
3577 3398 3718

output:

919081513
748091520
336370368
816414205
837085228
14931324
680497479
647476532
166908806
718496336

result:

ok 10 lines

Test #3:

score: 10
Accepted
time: 24ms
memory: 3880kb

input:

10
4519 4189 4072
4052 4002 4157
4230 4435 4363
4515 4028 4451
4399 4551 4688
4456 4358 4471
4109 4537 4572
4323 4752 4528
4361 4905 4348
4117 4434 4810

output:

420450298
615154420
32903889
958731225
922332838
39742175
66516020
632249329
424172857
465363232

result:

ok 10 lines

Test #4:

score: 10
Accepted
time: 151ms
memory: 4044kb

input:

10
17136 18154 18724
16629 12214 17413
15253 10155 13458
17096 13806 16769
15236 14354 18323
13094 19136 16852
17418 18188 17566
16275 10700 19227
18810 19912 11416
15327 12117 17119

output:

726077079
734135143
601896068
393530194
22020991
987568247
831587252
858154598
46655946
526713034

result:

ok 10 lines

Test #5:

score: 10
Accepted
time: 245ms
memory: 4072kb

input:

7
27755 28517 28482
28438 26289 28481
25044 27828 27248
25434 26802 26393
28156 25264 25282
25245 27052 27762
26292 27348 25746

output:

526394310
849807853
840092589
913471641
273455164
891473827
28209814

result:

ok 7 lines

Test #6:

score: 10
Accepted
time: 259ms
memory: 4308kb

input:

5
34705 34903 39485
36395 35236 38154
35777 38513 36847
37788 34468 35376
39645 39238 37169

output:

169462122
448448054
986623041
273945179
361303347

result:

ok 5 lines

Test #7:

score: 10
Accepted
time: 287ms
memory: 4596kb

input:

4
42495 48356 47796
45845 49516 42444
48928 42926 47681
44787 41256 49432

output:

912914940
421832759
944309862
324478867

result:

ok 4 lines

Test #8:

score: 10
Accepted
time: 404ms
memory: 5640kb

input:

2
83235 96187 90028
95824 85017 96145

output:

91596405
822433137

result:

ok 2 lines

Test #9:

score: 10
Accepted
time: 409ms
memory: 5720kb

input:

2
85017 81194 93250
99216 90392 97201

output:

694934048
780451544

result:

ok 2 lines

Test #10:

score: 10
Accepted
time: 479ms
memory: 5400kb

input:

2
100000 100000 99999
100000 99999 99999

output:

936290692
763871123

result:

ok 2 lines