QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418503#2586. 旧试题hos_lyric10 482ms5440kbC++145.7kb2024-05-23 14:16:382024-05-23 14:16:40

Judging History

This is the latest submission verdict.

  • [2024-05-23 14:16:40]
  • Judged
  • Verdict: 10
  • Time: 482ms
  • Memory: 5440kb
  • [2024-05-23 14:16:38]
  • Submitted

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 <= N; ++n) wtsA[n] = Sigma0[A / n];
    for (int n = 1; n <= N; ++n) wtsB[n] = Sigma0[B / n];
    for (int n = 1; n <= N; ++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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:


result:


Test #2:

score: 0
Runtime Error

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:


result:


Test #3:

score: 0
Runtime Error

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:


result:


Test #4:

score: 0
Runtime Error

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:


result:


Test #5:

score: 0
Runtime Error

input:

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

output:


result:


Test #6:

score: 0
Runtime Error

input:

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

output:


result:


Test #7:

score: 0
Runtime Error

input:

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

output:


result:


Test #8:

score: 0
Runtime Error

input:

2
83235 96187 90028
95824 85017 96145

output:


result:


Test #9:

score: 0
Runtime Error

input:

2
85017 81194 93250
99216 90392 97201

output:


result:


Test #10:

score: 10
Accepted
time: 482ms
memory: 5440kb

input:

2
100000 100000 99999
100000 99999 99999

output:

936290692
763871123

result:

ok 2 lines