QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418492#2586. 旧试题hos_lyric0 442ms5032kbC++145.5kb2024-05-23 14:13:572024-05-23 14:13:58

Judging History

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

  • [2024-05-23 14:13:58]
  • 评测
  • 测评结果:0
  • 用时:442ms
  • 内存:5032kb
  • [2024-05-23 14:13:57]
  • 提交

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> wts;
Int counter;
Mint ans;

void dfs(int i, int a, int b, int c, Mint t) {
++counter;
  ans += t * wts[a] * wts[b] * wts[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];
    wts.resize(N + 1);
    for (int n = 1; n <= N; ++n) wts[n] = Sigma0[N / 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 11ms
memory: 3908kb

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:

269318561
542705830
109991948
786718258
933727290
460339571
1531347
908535597
872625564
744070544

result:

wrong answer 1st lines differ - expected: '427265215', found: '269318561'

Test #2:

score: 0
Wrong Answer
time: 19ms
memory: 3936kb

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:

624517133
37950036
672073140
860387669
237523819
759775352
166664135
601995484
614842313
354840649

result:

wrong answer 1st lines differ - expected: '919081513', found: '624517133'

Test #3:

score: 0
Wrong Answer
time: 24ms
memory: 3960kb

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:

435693002
697381788
581619156
824757594
562962301
942603105
280825375
356801103
870866245
74492969

result:

wrong answer 1st lines differ - expected: '420450298', found: '435693002'

Test #4:

score: 0
Wrong Answer
time: 146ms
memory: 4020kb

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:

405660533
833698190
517796928
564480380
768002286
570646844
936307628
742320541
937763698
573191041

result:

wrong answer 1st lines differ - expected: '726077079', found: '405660533'

Test #5:

score: 0
Wrong Answer
time: 256ms
memory: 4076kb

input:

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

output:

4109925
78096069
167538584
690135277
621957756
851648970
703951533

result:

wrong answer 1st lines differ - expected: '526394310', found: '4109925'

Test #6:

score: 0
Wrong Answer
time: 261ms
memory: 4440kb

input:

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

output:

31532318
71216773
506555491
174342627
783562883

result:

wrong answer 1st lines differ - expected: '169462122', found: '31532318'

Test #7:

score: 0
Wrong Answer
time: 283ms
memory: 4204kb

input:

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

output:

690422543
652847287
846933347
946542147

result:

wrong answer 1st lines differ - expected: '912914940', found: '690422543'

Test #8:

score: 0
Wrong Answer
time: 389ms
memory: 4700kb

input:

2
83235 96187 90028
95824 85017 96145

output:

937399735
185875620

result:

wrong answer 1st lines differ - expected: '91596405', found: '937399735'

Test #9:

score: 0
Wrong Answer
time: 390ms
memory: 5032kb

input:

2
85017 81194 93250
99216 90392 97201

output:

125701601
434901815

result:

wrong answer 1st lines differ - expected: '694934048', found: '125701601'

Test #10:

score: 0
Wrong Answer
time: 442ms
memory: 4944kb

input:

2
100000 100000 99999
100000 99999 99999

output:

176764584
176764584

result:

wrong answer 1st lines differ - expected: '936290692', found: '176764584'