QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#734850 | #9612. 月亮的背面是粉红色的 | hos_lyric# | 84 | 2013ms | 539600kb | C++14 | 6.2kb | 2024-11-11 15:29:12 | 2024-11-11 15:29:14 |
Judging History
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];
void sieveInit(int N) {
fill(lpf, lpf + (N + 1), 0);
primesLen = 0;
}
void sieve(int N) {
moe[1] = 1;
for (int n = 2; n <= N; ++n) {
if (lpf[n] == 0) {
lpf[n] = n;
moe[n] = -1;
primes[primesLen++] = n;
}
for (int i = 0; i < primesLen && primes[i] <= lpf[n] && primes[i] * n <= N; ++i) {
lpf[primes[i] * n] = primes[i];
moe[primes[i] * n] = -moe[n];
}
}
for (int i = 0; i < primesLen; ++i) {
const int p2 = primes[i] * primes[i];
if (p2 > N) break;
for (int n = p2; n <= N; n += p2) moe[n] = 0;
}
}
int fs[LIM_SIEVE];
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);
Mint ans[2] = {};
{
// \sigma[0](n)
fs[1] = 1;
for (int n = 2; n <= sqrtN; ++n) {
const int p = lpf[n];
int e = 0;
int nn = n;
do { ++e; nn /= p; } while (nn % p == 0);
fs[n] = (e + 1) * fs[nn];
}
for (int n = 1; n <= sqrtN; ++n) fs[n] += fs[n - 1];
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;
}
}
if (M) {
// \sigma[0](n) n
for (int n = 1; n <= sqrtN; ++n) gs[n] = gs[n - 1] + (Int)n * (fs[n] - fs[n - 1]);
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);
}
}
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: 1ms
memory: 9964kb
input:
1726 1
output:
84290761 74619067
result:
ok 2 number(s): "84290761 74619067"
Test #2:
score: 3
Accepted
time: 1ms
memory: 10016kb
input:
3608 1
output:
433014481 672891299
result:
ok 2 number(s): "433014481 672891299"
Test #3:
score: 3
Accepted
time: 1ms
memory: 10156kb
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: 10044kb
input:
6116899 1
output:
219318963 301450440
result:
ok 2 number(s): "219318963 301450440"
Test #5:
score: 3
Accepted
time: 0ms
memory: 10196kb
input:
6260707 1
output:
148720176 263856753
result:
ok 2 number(s): "148720176 263856753"
Test #6:
score: 3
Accepted
time: 1ms
memory: 9892kb
input:
6763677 1
output:
944542490 136397156
result:
ok 2 number(s): "944542490 136397156"
Subtask #3:
score: 8
Accepted
Test #7:
score: 8
Accepted
time: 3ms
memory: 10268kb
input:
6469467712 0
output:
147393348
result:
ok 1 number(s): "147393348"
Test #8:
score: 8
Accepted
time: 0ms
memory: 12128kb
input:
8967004453 0
output:
229436583
result:
ok 1 number(s): "229436583"
Test #9:
score: 8
Accepted
time: 3ms
memory: 10292kb
input:
6636594384 0
output:
995965072
result:
ok 1 number(s): "995965072"
Subtask #4:
score: 8
Accepted
Test #10:
score: 8
Accepted
time: 6ms
memory: 12900kb
input:
8292948816 1
output:
566765721 287485757
result:
ok 2 number(s): "566765721 287485757"
Test #11:
score: 8
Accepted
time: 3ms
memory: 11180kb
input:
8592748771 1
output:
649470692 164561252
result:
ok 2 number(s): "649470692 164561252"
Test #12:
score: 8
Accepted
time: 3ms
memory: 11320kb
input:
9827380808 1
output:
291159931 188690805
result:
ok 2 number(s): "291159931 188690805"
Subtask #5:
score: 8
Accepted
Test #13:
score: 8
Accepted
time: 51ms
memory: 27784kb
input:
900472451132 1
output:
247050500 963765719
result:
ok 2 number(s): "247050500 963765719"
Test #14:
score: 8
Accepted
time: 52ms
memory: 28944kb
input:
850862494659 1
output:
200210720 915108650
result:
ok 2 number(s): "200210720 915108650"
Test #15:
score: 8
Accepted
time: 52ms
memory: 26296kb
input:
851346512859 1
output:
895785763 504512885
result:
ok 2 number(s): "895785763 504512885"
Subtask #6:
score: 10
Accepted
Test #16:
score: 10
Accepted
time: 184ms
memory: 64008kb
input:
9864907300784 1
output:
359943536 720268421
result:
ok 2 number(s): "359943536 720268421"
Test #17:
score: 10
Accepted
time: 170ms
memory: 58844kb
input:
8181674676063 1
output:
839993102 994056029
result:
ok 2 number(s): "839993102 994056029"
Test #18:
score: 10
Accepted
time: 175ms
memory: 66164kb
input:
9893510217522 1
output:
157499971 930653488
result:
ok 2 number(s): "157499971 930653488"
Subtask #7:
score: 13
Accepted
Test #19:
score: 13
Accepted
time: 326ms
memory: 100892kb
input:
96735749745529 0
output:
223354886
result:
ok 1 number(s): "223354886"
Test #20:
score: 13
Accepted
time: 312ms
memory: 98460kb
input:
95243570720799 0
output:
555372474
result:
ok 1 number(s): "555372474"
Test #21:
score: 13
Accepted
time: 331ms
memory: 101924kb
input:
97668723090105 0
output:
84562124
result:
ok 1 number(s): "84562124"
Subtask #8:
score: 14
Accepted
Test #22:
score: 14
Accepted
time: 582ms
memory: 176696kb
input:
94060593399194 1
output:
52991150 887133157
result:
ok 2 number(s): "52991150 887133157"
Test #23:
score: 14
Accepted
time: 601ms
memory: 178608kb
input:
98527940728119 1
output:
281611635 910356955
result:
ok 2 number(s): "281611635 910356955"
Test #24:
score: 14
Accepted
time: 574ms
memory: 169548kb
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: 1999ms
memory: 529232kb
input:
949243849085176 1
output:
508465534 771553755
result:
ok 2 number(s): "508465534 771553755"
Test #32:
score: 17
Accepted
time: 1946ms
memory: 523208kb
input:
924225524519163 1
output:
867410272 870831653
result:
ok 2 number(s): "867410272 870831653"
Test #33:
score: 17
Accepted
time: 2003ms
memory: 539504kb
input:
978079151303393 1
output:
235076358 675828942
result:
ok 2 number(s): "235076358 675828942"
Test #34:
score: 17
Accepted
time: 1945ms
memory: 521676kb
input:
929804617107620 1
output:
790604296 73162158
result:
ok 2 number(s): "790604296 73162158"
Test #35:
score: 17
Accepted
time: 2013ms
memory: 539600kb
input:
989806727450552 1
output:
378550840 783149232
result:
ok 2 number(s): "378550840 783149232"