QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153511#6519. X Equals Y275307894aWA 0ms3780kbC++141.6kb2023-08-30 09:21:152023-08-30 09:21:17

Judging History

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

  • [2023-08-30 09:21:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3780kb
  • [2023-08-30 09:21:15]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e5+5,M=N*40+5,K=600+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int x,y,A,B;
void print(int X,int Y){
	while(x||y){
		// assert(x%X==y%Y);
		x/=X;y/=Y;
	}
	printf("YES\n%d %d\n",X,Y);
}
map<vector<int>,int> f;
void Solve(){
	int i,j;scanf("%d%d%d%d",&x,&y,&A,&B);
	if(x==y) {printf("YES\n2 2\n");return;}
	int X=sqrt(x),Y=sqrt(y);
	for(i=2;i<=A&&i<=X;i++) {
		vector<int> c;
		int z=x;for(j=0;z;j++) c.emplace_back(z%i),z/=i;
		f[c]=i;
	}
	for(i=2;i<=B&&i<=Y;i++) {
		vector<int> c;
		int z=y;for(j=0;z;j++) c.emplace_back(z%i),z/=i;
		if(f.count(c)){print(f[c],i);return;}
	}
	X=max(X+1,2);Y=max(Y+1,2);
	while(X<=A&&Y<=B&&X<=x&&Y<=y){
		int l=min(A,x/(x/X)),r=min(B,y/(y/Y));
		if(x/X!=y/Y){
			if(x/X<y/Y) Y=r+1;else X=l+1;
			continue;
		}
		// cerr<<X<<' '<<Y<<'\n';
		int xl=x%X,xr=x%l,yl=y%Y,yr=y%r;
		if(xl%(x/X)==yl%(y/Y)&&max(xr,yr)<=min(xl,yl)) {
			int z=min(xl,yl);
			print(X+(xl-z)/(x/X),Y+(yl-z)/(y/Y));
			return;
		}
		X=l+1;Y=r+1;
	}
	puts("NO");
}
int main(){
	int t;
	scanf("%d",&t);
	// t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3780kb

input:

6
1 1 1000 1000
1 2 1000 1000
3 11 1000 1000
157 291 5 6
157 291 3 6
10126 114514 789 12345

output:

YES
2 2
NO
YES
2 10
YES
4 5
YES
4 5
YES
6 10

result:

wrong answer Integer parameter [name=a] equals to 4, violates the range [2, 3] (test case 5)