QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#734825 | #9612. 月亮的背面是粉红色的 | hos_lyric# | 67 | 1438ms | 181736kb | C++14 | 7.0kb | 2024-11-11 15:20:54 | 2024-11-11 15:20:55 |
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>;
inline long long divide(long long a, int b) {
return a / b;
}
inline long long divide(long long a, long long b) {
return a / b;
}
// quo[i - 1] < x <= quo[i] <=> floor(N/x) = quo[len - i] (1 <= i <= len - 1)
struct Quotients {
long long N;
int N2;
int len;
Quotients(long long N_ = 0) : N(N_) {
N2 = sqrt(static_cast<long double>(N));
len = 2 * N2 + ((static_cast<long long>(N2) * (N2 + 1) <= N) ? 1 : 0);
}
long long operator[](int i) const {
return (i <= N2) ? i : divide(N, len - i);
}
int indexOf(long long x) const {
return (x <= N2) ? x : (len - divide(N, x));
}
friend std::ostream &operator<<(std::ostream &os, const Quotients &quo) {
os << "[";
for (int i = 0; i < quo.len; ++i) {
if (i > 0) os << ", ";
os << quo[i];
}
os << "]";
return os;
}
};
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 = sqrt((long double)N);
sieve(sqrtN);
Mint ans[2] = {};
{
// \sigma[0]
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 Quotients quo(n);
for (int i = 1; i < quo.len; ++i) sum += (quo[i] - quo[i - 1]) * quo[quo.len - i];
}
ans[0] += moe[a] * sum;
}
}
if (M) {
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 {
const Quotients quo(n);
sum = 0;
for (int i = 1; i < quo.len; ++i) sum += (s1(quo[i]) - s1(quo[i - 1])) * s1(quo[quo.len - i]);
}
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: 9952kb
input:
1726 1
output:
84290761 74619067
result:
ok 2 number(s): "84290761 74619067"
Test #2:
score: 3
Accepted
time: 1ms
memory: 10024kb
input:
3608 1
output:
433014481 672891299
result:
ok 2 number(s): "433014481 672891299"
Test #3:
score: 3
Accepted
time: 1ms
memory: 10160kb
input:
2921 1
output:
271096225 547734266
result:
ok 2 number(s): "271096225 547734266"
Subtask #2:
score: 3
Accepted
Test #4:
score: 3
Accepted
time: 1ms
memory: 9860kb
input:
6116899 1
output:
219318963 301450440
result:
ok 2 number(s): "219318963 301450440"
Test #5:
score: 3
Accepted
time: 0ms
memory: 10004kb
input:
6260707 1
output:
148720176 263856753
result:
ok 2 number(s): "148720176 263856753"
Test #6:
score: 3
Accepted
time: 0ms
memory: 10208kb
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: 10404kb
input:
6469467712 0
output:
147393348
result:
ok 1 number(s): "147393348"
Test #8:
score: 8
Accepted
time: 7ms
memory: 12224kb
input:
8967004453 0
output:
229436583
result:
ok 1 number(s): "229436583"
Test #9:
score: 8
Accepted
time: 6ms
memory: 10412kb
input:
6636594384 0
output:
995965072
result:
ok 1 number(s): "995965072"
Subtask #4:
score: 8
Accepted
Test #10:
score: 8
Accepted
time: 8ms
memory: 14592kb
input:
8292948816 1
output:
566765721 287485757
result:
ok 2 number(s): "566765721 287485757"
Test #11:
score: 8
Accepted
time: 12ms
memory: 10920kb
input:
8592748771 1
output:
649470692 164561252
result:
ok 2 number(s): "649470692 164561252"
Test #12:
score: 8
Accepted
time: 8ms
memory: 11324kb
input:
9827380808 1
output:
291159931 188690805
result:
ok 2 number(s): "291159931 188690805"
Subtask #5:
score: 8
Accepted
Test #13:
score: 8
Accepted
time: 128ms
memory: 27280kb
input:
900472451132 1
output:
247050500 963765719
result:
ok 2 number(s): "247050500 963765719"
Test #14:
score: 8
Accepted
time: 117ms
memory: 28292kb
input:
850862494659 1
output:
200210720 915108650
result:
ok 2 number(s): "200210720 915108650"
Test #15:
score: 8
Accepted
time: 118ms
memory: 25864kb
input:
851346512859 1
output:
895785763 504512885
result:
ok 2 number(s): "895785763 504512885"
Subtask #6:
score: 10
Accepted
Test #16:
score: 10
Accepted
time: 443ms
memory: 64440kb
input:
9864907300784 1
output:
359943536 720268421
result:
ok 2 number(s): "359943536 720268421"
Test #17:
score: 10
Accepted
time: 401ms
memory: 59236kb
input:
8181674676063 1
output:
839993102 994056029
result:
ok 2 number(s): "839993102 994056029"
Test #18:
score: 10
Accepted
time: 439ms
memory: 66316kb
input:
9893510217522 1
output:
157499971 930653488
result:
ok 2 number(s): "157499971 930653488"
Subtask #7:
score: 13
Accepted
Test #19:
score: 13
Accepted
time: 705ms
memory: 101016kb
input:
96735749745529 0
output:
223354886
result:
ok 1 number(s): "223354886"
Test #20:
score: 13
Accepted
time: 702ms
memory: 97836kb
input:
95243570720799 0
output:
555372474
result:
ok 1 number(s): "555372474"
Test #21:
score: 13
Accepted
time: 710ms
memory: 101168kb
input:
97668723090105 0
output:
84562124
result:
ok 1 number(s): "84562124"
Subtask #8:
score: 14
Accepted
Test #22:
score: 14
Accepted
time: 1415ms
memory: 176812kb
input:
94060593399194 1
output:
52991150 887133157
result:
ok 2 number(s): "52991150 887133157"
Test #23:
score: 14
Accepted
time: 1438ms
memory: 181736kb
input:
98527940728119 1
output:
281611635 910356955
result:
ok 2 number(s): "281611635 910356955"
Test #24:
score: 14
Accepted
time: 1394ms
memory: 173576kb
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: 0
Time Limit Exceeded
Test #31:
score: 0
Time Limit Exceeded
input:
949243849085176 1