QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#461728 | #4278. GCD vs LCM | propane | WA | 23ms | 6620kb | C++20 | 2.2kb | 2024-07-03 00:19:00 | 2024-07-03 00:19:00 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<array>
using namespace std;
using LL = long long;
const int mod = 1e9 + 7;
void add(int &a, int b){
a += b;
if (a >= mod) a -= mod;
}
int mul(int a, int b){
return 1LL * a * b % mod;
}
const int maxn = 1e5 + 5;
int mu[maxn];
vector<int> prime;
bool isPrime[maxn];
void init(){
mu[1] = 1;
for(int i = 2; i < maxn; i++){
if (!isPrime[i]){
prime.push_back(i);
mu[i] = -1;
}
for(auto p : prime){
if (i * p > maxn) break;
isPrime[i * p] = true;
if (p % i == 0) break;
mu[i * p] = -mu[i];
}
}
}
int tr[maxn];
int lowbit(int x){
return x & -x;
}
void modify(int x, int v){
if (v < 0) v += mod;
while(x < maxn){
add(tr[x], v);
x += lowbit(x);
}
}
int sum(int x){
int ans = 0;
while(x){
add(ans, tr[x]);
x -= lowbit(x);
}
return ans;
}
int sum(int l, int r){
return sum(r) - sum(l - 1);
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
init();
const int N = 1e5;
vector<vector<array<int, 3> > > query(N + 1);
int q;
cin >> q;
for(int i = 0; i < q; i++){
int n, m, a;
cin >> n >> m >> a;
query[a].push_back({n, m, i});
}
auto f = [&](int x){
return int(1LL * x * (x + 1) / 2 % mod);
};
vector<int> ans(q);
for(int i = 1; i <= N; i++){
for(int j = i; j <= N; j += i){
int t = mu[j / i];
if (t < 0) t += mod;
t = mul(t, j);
t = mul(t, j / i);
modify(j, t);
}
for(auto [n, m, id] : query[i]){
int t = min(n, m);
int s = 0;
for(int l = 1, r; l <= t; l = r + 1){
r = min(n / (n / l), m / (m / l));
add(s, mul(sum(l, r), mul(f(n / l), f(m / l))));
}
ans[id] = s;
}
}
for(auto x : ans) cout << x << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 23ms
memory: 6592kb
input:
2 2 2 1 3 4 2
output:
5 45
result:
ok 2 number(s): "5 45"
Test #2:
score: 0
Accepted
time: 23ms
memory: 6620kb
input:
5 2 8 4 10 2 9 7 8 3 2 5 10 5 2 4
output:
88 135 742 39 39
result:
ok 5 number(s): "88 135 742 39 39"
Test #3:
score: -100
Wrong Answer
time: 20ms
memory: 6552kb
input:
5 17 8 8 27 17 10 38 46 2 37 42 1 46 13 1
output:
4164 42652 541949 378860 60919
result:
wrong answer 2nd numbers differ - expected: '43084', found: '42652'