QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#734776 | #9612. 月亮的背面是粉红色的 | hos_lyric# | 53 | 1043ms | 58500kb | C++14 | 6.4kb | 2024-11-11 15:03:32 | 2024-11-11 15:03:32 |
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;
}
}
__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] = {};
for (int a = 1; a <= sqrtN; ++a) if (moe[a]) {
const Int n = N / ((Int)a * a);
const Quotients quo(n);
/*
[1, 2, 3, 4, ...]
\sum[0<b<=n] floor(n/b)
*/
{
Int sum = 0;
for (int i = 1; i < quo.len; ++i) sum += (quo[i] - quo[i - 1]) * quo[quo.len - i];
ans[0] += moe[a] * sum;
}
/*
[1, 2p, 3p^2, 4p^3, ...]
\sum[0<b<=n] b floor(n/b) (floor(n/b)+1)/2
*/
if (M) {
__int128 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: 6064kb
input:
1726 1
output:
84290761 74619067
result:
ok 2 number(s): "84290761 74619067"
Test #2:
score: 3
Accepted
time: 1ms
memory: 6136kb
input:
3608 1
output:
433014481 672891299
result:
ok 2 number(s): "433014481 672891299"
Test #3:
score: 3
Accepted
time: 1ms
memory: 5852kb
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: 5856kb
input:
6116899 1
output:
219318963 301450440
result:
ok 2 number(s): "219318963 301450440"
Test #5:
score: 3
Accepted
time: 1ms
memory: 5932kb
input:
6260707 1
output:
148720176 263856753
result:
ok 2 number(s): "148720176 263856753"
Test #6:
score: 3
Accepted
time: 1ms
memory: 5928kb
input:
6763677 1
output:
944542490 136397156
result:
ok 2 number(s): "944542490 136397156"
Subtask #3:
score: 8
Accepted
Test #7:
score: 8
Accepted
time: 7ms
memory: 8196kb
input:
6469467712 0
output:
147393348
result:
ok 1 number(s): "147393348"
Test #8:
score: 8
Accepted
time: 8ms
memory: 6528kb
input:
8967004453 0
output:
229436583
result:
ok 1 number(s): "229436583"
Test #9:
score: 8
Accepted
time: 7ms
memory: 8456kb
input:
6636594384 0
output:
995965072
result:
ok 1 number(s): "995965072"
Subtask #4:
score: 8
Accepted
Test #10:
score: 8
Accepted
time: 17ms
memory: 6296kb
input:
8292948816 1
output:
566765721 287485757
result:
ok 2 number(s): "566765721 287485757"
Test #11:
score: 8
Accepted
time: 13ms
memory: 6376kb
input:
8592748771 1
output:
649470692 164561252
result:
ok 2 number(s): "649470692 164561252"
Test #12:
score: 8
Accepted
time: 14ms
memory: 8596kb
input:
9827380808 1
output:
291159931 188690805
result:
ok 2 number(s): "291159931 188690805"
Subtask #5:
score: 8
Accepted
Test #13:
score: 8
Accepted
time: 183ms
memory: 10600kb
input:
900472451132 1
output:
247050500 963765719
result:
ok 2 number(s): "247050500 963765719"
Test #14:
score: 8
Accepted
time: 181ms
memory: 13148kb
input:
850862494659 1
output:
200210720 915108650
result:
ok 2 number(s): "200210720 915108650"
Test #15:
score: 8
Accepted
time: 181ms
memory: 13528kb
input:
851346512859 1
output:
895785763 504512885
result:
ok 2 number(s): "895785763 504512885"
Subtask #6:
score: 10
Accepted
Test #16:
score: 10
Accepted
time: 670ms
memory: 22764kb
input:
9864907300784 1
output:
359943536 720268421
result:
ok 2 number(s): "359943536 720268421"
Test #17:
score: 10
Accepted
time: 610ms
memory: 23164kb
input:
8181674676063 1
output:
839993102 994056029
result:
ok 2 number(s): "839993102 994056029"
Test #18:
score: 10
Accepted
time: 673ms
memory: 25996kb
input:
9893510217522 1
output:
157499971 930653488
result:
ok 2 number(s): "157499971 930653488"
Subtask #7:
score: 13
Accepted
Test #19:
score: 13
Accepted
time: 1033ms
memory: 58500kb
input:
96735749745529 0
output:
223354886
result:
ok 1 number(s): "223354886"
Test #20:
score: 13
Accepted
time: 1033ms
memory: 58212kb
input:
95243570720799 0
output:
555372474
result:
ok 1 number(s): "555372474"
Test #21:
score: 13
Accepted
time: 1043ms
memory: 57424kb
input:
97668723090105 0
output:
84562124
result:
ok 1 number(s): "84562124"
Subtask #8:
score: 0
Time Limit Exceeded
Test #22:
score: 0
Time Limit Exceeded
input:
94060593399194 1
output:
result:
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