QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#196468 | #6519. X Equals Y | ucup-team870# | WA | 2ms | 3564kb | C++14 | 1.5kb | 2023-10-01 17:53:25 | 2023-10-01 17:53:27 |
Judging History
answer
#include <bits/stdc++.h>
#define For(i,l,r) for(int i=l; i<=r; i++)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
bool flag;
void pr(ll a,ll b){
cout<<"YES\n";
if (!flag) cout<<a<<' '<<b<<'\n';
else cout<<b<<' '<<a<<'\n';
}
ll q[105],l;
int main(){
int _; cin>>_;
while(_--){
ll x,y,A,B; cin>>x>>y>>A>>B;
if (x==y) {cout<<"YES\n2 2\n"; continue;}
if (x<y){
flag=0;
}
else{
flag=1;
swap(x,y); swap(A,B);
}
//2
ll st=sqrt(y-x); bool ff=0;
For(c,1,st) if ((y-x)%c==0){
ll dt=(y-x)/c;
ll a=min(min(A,B-dt),x/c),d=x-a*c;
if (a>c&&a>d){
pr(a,a+dt); ff=1; break;
}
}
if (ff) continue;
//3
st=sqrt(x); int b=3;
For(a,2,st){
// cal q
l=0;
ll xx=x;
while(xx){
q[l]=xx%a; xx=xx/a; ++l;
}
// cal y
b=max(b,a+1); ll yy,bb;
while(1){
yy=0,bb=1;
For(i,0,l-1){
yy=yy+q[i]*bb; bb=bb*b;
}
if (yy>=y) break;
++b;
}
if (yy==y&&a<=A&&b<=B) {pr(a,b); goto E;}
}
cout<<"NO\n";
E:;
}
}
/*
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
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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 3 11 YES 4 5 NO YES 789 9488
result:
ok correct (6 test cases)
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3536kb
input:
1000 920 661 756 534 52 454 31 218 980 77 812 6 729 733 289 660 161 643 21 475 602 525 329 274 782 167 279 113 875 100 388 16 426 498 341 417 433 751 312 39 91 50 47 39 941 388 247 46 725 808 148 486 945 405 700 145 647 509 152 445 45 564 16 468 843 40 530 3 722 36 323 22 568 472 443 41 38 749 25 42...
output:
YES 756 497 YES 17 151 NO YES 289 291 NO YES 86 75 YES 260 55 NO YES 341 413 NO NO NO NO YES 415 145 YES 107 84 YES 15 188 NO NO NO YES 12 249 NO NO YES 196 20 YES 151 120 NO YES 750 346 NO YES 67 196 NO YES 66 29 NO NO YES 94 54 YES 6 5 NO NO NO NO NO YES 324 129 NO YES 237 224 YES 211 411 YES 288 ...
result:
wrong answer you didn't find a solution but jury did (test case 19)