QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#842141 | #9962. Diminishing Fractions | ucup-team1004# | WA | 184ms | 210000kb | C++14 | 1.3kb | 2025-01-04 10:28:32 | 2025-01-04 10:28:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e4+10,M=1e4;
int p[N],len,vis[N],g[N];
vector<int> v;
int f[M][M];
void init(int n)
{
for(int i=2;i<=n;i++)
{
if(!vis[i]) p[++len]=vis[i]=i;
for(int j=1;j<=len&&i*p[j]<=n;j++)
{
vis[i*p[j]]=p[j];
if(i%p[j]==0) break;
}
}
for(int i=1;i<=len;i++)
{
int x=1;
while(x<=n/p[i]) x*=p[i],g[x]=1;
}
for(int i=1;i<=n;i++)
if(g[i]) v.push_back(i),g[i]=v.size();
int m=v.size();
for(int i=1;i<=m;i++)
{
int s=1,x=v[i-1];
for(int j=1;j<=m;j++)
{
int y=v[j-1];
if(vis[x]!=vis[y]) s=1ll*s*vis[y]%x;
f[i][j]=s;
}
}
}
int fastpow(int x,int y,int mod)
{
int s=1;
for(;y;y>>=1,x=1ll*x*x%mod)
if(y&1) s=1ll*s*x%mod;
return s;
}
int inv(int x,int y)
{
return fastpow(x,y/vis[y]*(vis[y]-1)-1,y);
}
int main()
{
init(5e4);
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
if(n==1)
{
puts("1/1");
continue;
}
int m=n,flag=0;
while(!g[m]) m--;
m=g[m];
double s=0;
for(int i=1;i<=m;i++)
{
int x=v[i-1];
if(1ll*x*vis[x]<=n) continue;
int y=inv(f[i][m],x);
if(!flag) flag=1;
else putchar('+');
printf("%d/%d",y,x);
s+=1.*y/x;
}
if(s>=1) printf("-%d/1\n",(int)s),s-=(int)s;
else puts("");
// printf("%.10lf\n",1/s);
}
}
详细
Test #1:
score: 100
Accepted
time: 184ms
memory: 210000kb
input:
2 3 6
output:
1/2+2/3-1/1 2/3+3/4+3/5-2/1
result:
ok OK, t = 2
Test #2:
score: 0
Accepted
time: 183ms
memory: 209708kb
input:
1 1
output:
1/1
result:
ok OK, t = 1
Test #3:
score: 0
Accepted
time: 179ms
memory: 209636kb
input:
10 1 2 3 4 5 6 7 8 9 10
output:
1/1 1/2 1/2+2/3-1/1 1/3+3/4-1/1 2/3+3/4+3/5-2/1 2/3+3/4+3/5-2/1 2/3+1/4+4/5+2/7-2/1 1/3+2/5+1/7+1/8-1/1 4/5+5/7+3/8+1/9-2/1 4/5+5/7+3/8+1/9-2/1
result:
ok OK, t = 10
Test #4:
score: -100
Wrong Answer
time: 175ms
memory: 207952kb
input:
54 7 20 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 3 47 81
output:
2/3+1/4+4/5+2/7-2/1 3/5+2/7+5/9+9/11+4/13+15/16+12/17+15/19-5/1 1/2 1/2+2/3-1/1 1/3+3/4-1/1 2/3+3/4+3/5-2/1 2/3+3/4+3/5-2/1 2/3+1/4+4/5+2/7-2/1 1/3+2/5+1/7+1/8-1/1 4/5+5/7+3/8+1/9-2/1 4/5+5/7+3/8+1/9-2/1 4/5+3/7+1/8+5/9+1/11-2/1 4/5+3/7+1/8+5/9+1/11-2/1 3/5+4/7+5/8+8/9+6/11+10/13-4/1 3/5+4/7+5/8+8/9...
result:
wrong answer Sums do not match for modulus 8809877585262195773