QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#359049 | #6519. X Equals Y | PorNPtree | WA | 7ms | 4032kb | C++14 | 2.6kb | 2024-03-20 11:31:05 | 2024-03-20 11:31:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int B = 1000000007;
signed main()
{
int T;
scanf("%d", &T);
for (int test = 1; test <= T; ++test) {
int x, y, A, B;
scanf("%d%d%d%d", &x, &y, &A, &B);
if (test >= 200) {
cerr << x << " " << y << " " << A << " " << B << endl;
}
if (x == y) {
puts("YES");
puts("2 2");
} else if (x == 1 || y == 1) {
puts("NO");
} else {
unordered_map<unsigned long long, int> M;
for (int i = 2; i * i <= x && i <= A; ++i) {
unsigned long long z = 3, tz = x;
while (tz) {
z = z * B + tz % i + 17;
tz /= i;
}
M[z] = i;
}
int flg = 0;
for (int i = 2; i * i <= y && i <= B; ++i) {
unsigned long long z = 3, tz = y;
while (tz) {
z = z * B + tz % i + 17;
tz /= i;
}
if (M.count(z)) {
puts("YES");
printf("%d %d\n", M[z], i);
flg = 1;
break;
}
}
if (!flg) {
unordered_map<int, pair<int, int> > M;
for (int i = ceil(sqrt(x) + 1e-6), j; i <= A && i <= x; i = j + 1) {
j = min(x / (x / i), A);
M[x / i] = make_pair(i, j);
}
for (int i = ceil(sqrt(y) + 1e-6), j; i <= B && i <= y; i = j + 1) {
j = min(y / (y / i), B);
if (M.count(y / i) && !((y - x) % (y / i))) {
int l1 = M[y / i].first, r1 = M[y / i].second;
int l2 = i, r2 = j, V = (y - x) / (y / i);
if (l2 - r1 <= V && r2 - l1 >= V) {
puts("YES");
int dl = V - (l2 - r1);
if (dl <= r2 - l2) {
printf("%d %d\n", r1, l2 + dl);
} else {
printf("%d %d\n", r1 - (dl - (r2 - l2)), r2);
}
flg = 1;
break;
}
}
}
if (!flg) {
puts("NO");
}
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3728kb
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 6 10
result:
ok correct (6 test cases)
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 4032kb
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 131 94 YES 8 75 NO YES 182 183 NO YES 54 47 YES 25 10 NO YES 23 27 NO NO NO NO YES 52 22 YES 107 84 YES 15 188 NO NO YES 35 29 YES 12 249 NO NO YES 16 5 YES 151 120 NO YES 249 148 NO YES 22 65 NO YES 66 29 NO NO YES 37 21 YES 6 5 NO NO NO NO NO YES 43 17 NO YES 38 36 YES 17 25 YES 96 15 NO NO NO...
result:
wrong answer wrong solution, (234 in base 6) != (9 in base 2) (test case 208)