QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#860309#9962. Diminishing Fractionsmzmz001#WA 115ms33052kbC++141.3kb2025-01-18 12:17:122025-01-18 12:17:13

Judging History

你现在查看的是最新测评结果

  • [2025-01-18 12:17:13]
  • 评测
  • 测评结果:WA
  • 用时:115ms
  • 内存:33052kb
  • [2025-01-18 12:17:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
long long n=5e4,m,k,l,f[1000007],T,a1,b[1000007],js,gs,wi;
int bo[4000007],sh[4000007];
vector<int>ve[1000007];
int am[1007][5207],an[1007][5207],si[1007];
long long inv(long long x,long long y){return x>1?y-inv(y%x,x)*y/x:1;}
double an1;
int main(){
	for(int i=2;i<=n;i++){
		if(!bo[i]){++gs;
			for(int j=i+i;j<=n;j+=i)bo[j]=1;
			for(int j=i;j<=n;j=j*i){
				sh[j]=i;
				if(j>n/i)break;
			}
		}
	}
	cin>>T;
	for(int u=1;u<=T;u++){
		scanf("%lld",&a1);
		ve[a1].push_back(u);
	}
	for(int i=1;i<=n;i++){
		if(sh[i]){
			if(sh[i]>b[js])b[++js]=sh[i];bo[sh[i]]=i;
			f[sh[i]]=1;
			for(int j=1;j<=js;j++){
				if(b[j]!=sh[i]){
					f[b[j]]=f[b[j]]*sh[i]%bo[b[j]];
					f[sh[i]]=f[sh[i]]*bo[b[j]]%i;
				}
			}
		}
		if(ve[i].size()){
			
			for(int j:ve[i]){
				if(i==1){
					si[j]=-1;
					continue;
				}
				si[j]=js;
				for(int o=1;o<=js;o++)am[j][o]=bo[b[o]],an[j][o]=f[b[o]];	
			}
		}
	}
	for(int u=1;u<=T;u++){
		if(si[u]==-1)puts("1/1");
		else{
			an1=0;
			for(int i=1;i<=si[u];i++){
				an[u][i]=inv(an[u][i]%am[u][i],am[u][i]);
				an1+=(double)an[u][i]/am[u][i];
			}
			int s=floor(an1);
			for(int i=1;i<=si[u];i++){
				printf("%d/%d",an[u][i],am[u][i]);
				if(i!=si[u])printf("+");
			}
			if(s)printf("-%d/1",s/1);;
			puts("");
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 114ms
memory: 32800kb

input:

2
3
6

output:

1/2+2/3-1/1
3/4+2/3+3/5-2/1

result:

ok OK, t = 2

Test #2:

score: 0
Accepted
time: 114ms
memory: 30748kb

input:

1
1

output:

1/1

result:

ok OK, t = 1

Test #3:

score: 0
Accepted
time: 115ms
memory: 32796kb

input:

10
1
2
3
4
5
6
7
8
9
10

output:

1/1
1/2
1/2+2/3-1/1
3/4+1/3-1/1
3/4+2/3+3/5-2/1
3/4+2/3+3/5-2/1
1/4+2/3+4/5+2/7-2/1
1/8+1/3+2/5+1/7-1/1
3/8+1/9+4/5+5/7-2/1
3/8+1/9+4/5+5/7-2/1

result:

ok OK, t = 10

Test #4:

score: -100
Wrong Answer
time: 115ms
memory: 33052kb

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:

1/4+2/3+4/5+2/7-2/1
15/16+5/9+3/5+2/7+9/11+4/13+12/17+15/19-5/1
1/2
1/2+2/3-1/1
3/4+1/3-1/1
3/4+2/3+3/5-2/1
3/4+2/3+3/5-2/1
1/4+2/3+4/5+2/7-2/1
1/8+1/3+2/5+1/7-1/1
3/8+1/9+4/5+5/7-2/1
3/8+1/9+4/5+5/7-2/1
1/8+5/9+4/5+3/7+1/11-2/1
1/8+5/9+4/5+3/7+1/11-2/1
5/8+8/9+3/5+4/7+6/11+10/13-4/1
5/8+8/9+3/5+4/7...

result:

wrong answer Sums do not match for modulus 8809877585262195773