QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#849763 | #9962. Diminishing Fractions | as_lyr | WA | 588ms | 7176kb | C++14 | 1.6kb | 2025-01-09 18:07:57 | 2025-01-09 18:07:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=51000;
int n=5e4,q;
int ask[N];
vector <int> v[N];
vector <pair<int,int>> e[N];
int a[N],b[N],c[N];
int t,p[N];
int val[N];
bool o[N];
inline int pw(int x,int y,const int mod){
int z=1;
while(y){
if(y&1)
z=1ll*z*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return z;
}
int main(){
scanf("%d",&q);
for(int i=1;i<=q;i++){
scanf("%d",&ask[i]);
v[ask[i]].push_back(i);
}
for(int i=2;i<=n;i++){
if(a[i]==0){
a[i]=b[i]=i;
p[++t]=i;
}
if(b[i]){
for(int j=1;j<i;j++)
if(a[j]==j&&b[i]!=j&&c[b[i]]){
val[j]=1ll*val[j]*pw(c[b[i]],c[j]/j*(j-1)-1,c[j])%c[j];
}
for(int j=1;j<i;j++)
if(a[j]==j&&b[i]!=j){
val[j]=1ll*val[j]*i%c[j];
}
c[b[i]]=i;
val[b[i]]=1;
for(int j=1;j<i;j++)
if(a[j]==j&&b[i]!=j)
val[b[i]]=1ll*val[b[i]]*c[j]%i;
}
for(int id:v[i])
for(int j=1;j<=i;j++)
if(a[j]==j)
e[id].push_back(make_pair(pw(val[j],c[j]/j*(j-1)-1,c[j]),c[j]));
for(int j=1;j<=t&&i*p[j]<=n;j++){
a[i*p[j]]=p[j];
b[i*p[j]]=b[i]==p[j]?b[i]:0;
if(a[i]==p[j])
break;
}
}
for(int i=1;i<=q;i++){
int x=ask[i];
if(x==1){
printf("1/1\n");
continue;
}
for(int j=1;j<=x;j++)
o[j]=0;
double sum=0;
bool ok=0;
for(auto pr:e[i]){
if(ok)
putchar('+');
printf("%d/%d",pr.first,pr.second);
sum+=1.0*pr.first/pr.second;
ok=1;
o[pr.second]=1;
}
int y=(int)floor(sum+0.5);
for(int j=1;y&&j<=x;j++){
if(o[j])
continue;
y--;
printf("-%d/%d",j,j);
}
puts("");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 588ms
memory: 6996kb
input:
2 3 6
output:
1/2+2/3-1/1 3/4+2/3+3/5-1/1-2/2
result:
ok OK, t = 2
Test #2:
score: 0
Accepted
time: 584ms
memory: 6932kb
input:
1 1
output:
1/1
result:
ok OK, t = 1
Test #3:
score: -100
Wrong Answer
time: 580ms
memory: 7176kb
input:
10 1 2 3 4 5 6 7 8 9 10
output:
1/1 1/2-1/1 1/2+2/3-1/1 3/4+1/3-1/1 3/4+2/3+3/5-1/1-2/2 3/4+2/3+3/5-1/1-2/2 1/4+2/3+4/5+2/7-1/1-2/2 1/8+1/3+2/5+1/7-1/1 3/8+1/9+4/5+5/7-1/1-2/2 3/8+1/9+4/5+5/7-1/1-2/2
result:
wrong answer Sums do not match for modulus 8809877585262195773