QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67480 | #2586. 旧试题 | alpha1022 | 100 ✓ | 533ms | 32428kb | C++23 | 3.0kb | 2022-12-10 16:22:56 | 2022-12-10 16:22:57 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5;
const long long mod = 1e9 + 7;
int T,A,B,C,mx,mn;
int vis[N + 5],cnt,prime[N + 5],mu[N + 5];
long long f[3][N + 5],ans;
int deg[N + 5];
vector<int> e[N + 5];
vector<long long> v[N + 5];
struct Edge
{
int u,v,w;
} g[(N << 4) + 5];
int tot;
int main()
{
mu[1] = 1;
for(register int i = 2;i <= N;++i)
{
if(!vis[i])
mu[prime[++cnt] = i] = -1;
for(register int j = 1;j <= cnt && i * prime[j] <= N;++j)
{
vis[i * prime[j]] = 1;
if(!(i % prime[j]))
break;
else
mu[i * prime[j]] = -mu[i];
}
}
memset(vis,0,sizeof vis);
scanf("%d",&T);
for(;T;--T)
{
scanf("%d%d%d",&A,&B,&C),mx = max(A,max(B,C)),mn = min(A,min(B,C)),ans = 0,memset(f,0,sizeof f);
for(register int i = 1;i <= A;++i)
for(register int j = i;j <= A;j += i)
f[0][i] += A / j;
for(register int i = 1;i <= B;++i)
for(register int j = i;j <= B;j += i)
f[1][i] += B / j;
for(register int i = 1;i <= C;++i)
for(register int j = i;j <= C;j += i)
f[2][i] += C / j;
for(register int i = 1;i <= mn;++i)
mu[i] && (ans += mu[i] * mu[i] * mu[i] * f[0][i] * f[1][i] * f[2][i]);
memset(deg,0,sizeof deg),tot = 0;
for(register int d = 1;d <= mx;++d)
for(register int i = 1;i * d <= mx;++i)
if(mu[i * d])
for(register int j = i + 1,x,y,lcm;(long long)i * j * d <= mx;++j)
if(mu[j * d] && __gcd(i,j) == 1)
x = i * d,y = j * d,lcm = i * j * d,
ans += mu[x] * mu[x] * mu[y] * (
f[0][x] * f[1][lcm] * f[2][lcm] +
f[0][lcm] * f[1][x] * f[2][lcm] +
f[0][lcm] * f[1][lcm] * f[2][x]),
ans += mu[x] * mu[y] * mu[y] * (
f[0][y] * f[1][lcm] * f[2][lcm] +
f[0][lcm] * f[1][y] * f[2][lcm] +
f[0][lcm] * f[1][lcm] * f[2][y]),
++deg[x],++deg[y],g[++tot] = (Edge){x,y,lcm};
for(register int i = 1;i <= mx;++i)
e[i].clear(),v[i].clear();
for(register int i = 1;i <= tot;++i)
if(deg[g[i].u] > deg[g[i].v] || (deg[g[i].u] == deg[g[i].v] && g[i].u < g[i].v))
e[g[i].u].push_back(g[i].v),v[g[i].u].push_back(g[i].w);
else
e[g[i].v].push_back(g[i].u),v[g[i].v].push_back(g[i].w);
for(register int x = 1;x <= mx;++x)
if(mu[x])
{
for(register int i = 0;i < e[x].size();++i)
vis[e[x][i]] = v[x][i];
for(register int i = 0,y,xy;i < e[x].size() && (y = e[x][i],xy = v[x][i],1);++i)
if(mu[y])
for(register int j = 0,z,xz,yz;j < e[y].size() && (z = e[y][j],xz = vis[z],yz = v[y][j],1);++j)
if(xz && mu[z])
ans += mu[x] * mu[y] * mu[z] * (
f[0][xy] * f[1][xz] * f[2][yz] +
f[0][xy] * f[1][yz] * f[2][xz] +
f[0][xz] * f[1][xy] * f[2][yz] +
f[0][xz] * f[1][yz] * f[2][xy] +
f[0][yz] * f[1][xy] * f[2][xz] +
f[0][yz] * f[1][xz] * f[2][xy]
);
for(register int i = 0;i < e[x].size();++i)
vis[e[x][i]] = 0;
}
printf("%lld\n",ans % mod);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 15ms
memory: 11612kb
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:
427265215 845145293 265815811 249115533 183034505 150848053 247869267 904260863 862484831 861301172
result:
ok 10 lines
Test #2:
score: 10
Accepted
time: 21ms
memory: 11824kb
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:
919081513 748091520 336370368 816414205 837085228 14931324 680497479 647476532 166908806 718496336
result:
ok 10 lines
Test #3:
score: 10
Accepted
time: 29ms
memory: 11908kb
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:
420450298 615154420 32903889 958731225 922332838 39742175 66516020 632249329 424172857 465363232
result:
ok 10 lines
Test #4:
score: 10
Accepted
time: 190ms
memory: 14624kb
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:
726077079 734135143 601896068 393530194 22020991 987568247 831587252 858154598 46655946 526713034
result:
ok 10 lines
Test #5:
score: 10
Accepted
time: 263ms
memory: 16304kb
input:
7 27755 28517 28482 28438 26289 28481 25044 27828 27248 25434 26802 26393 28156 25264 25282 25245 27052 27762 26292 27348 25746
output:
526394310 849807853 840092589 913471641 273455164 891473827 28209814
result:
ok 7 lines
Test #6:
score: 10
Accepted
time: 285ms
memory: 18496kb
input:
5 34705 34903 39485 36395 35236 38154 35777 38513 36847 37788 34468 35376 39645 39238 37169
output:
169462122 448448054 986623041 273945179 361303347
result:
ok 5 lines
Test #7:
score: 10
Accepted
time: 358ms
memory: 20516kb
input:
4 42495 48356 47796 45845 49516 42444 48928 42926 47681 44787 41256 49432
output:
912914940 421832759 944309862 324478867
result:
ok 4 lines
Test #8:
score: 10
Accepted
time: 505ms
memory: 30852kb
input:
2 83235 96187 90028 95824 85017 96145
output:
91596405 822433137
result:
ok 2 lines
Test #9:
score: 10
Accepted
time: 505ms
memory: 31660kb
input:
2 85017 81194 93250 99216 90392 97201
output:
694934048 780451544
result:
ok 2 lines
Test #10:
score: 10
Accepted
time: 533ms
memory: 32428kb
input:
2 100000 100000 99999 100000 99999 99999
output:
936290692 763871123
result:
ok 2 lines