QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#512369#9167. Coprime Arrayucup-team3723#WA 3ms7120kbC++201.4kb2024-08-10 14:19:032024-08-10 14:19:03

Judging History

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

  • [2024-08-11 17:38:28]
  • hack成功,自动添加数据
  • (/hack/775)
  • [2024-08-10 14:19:03]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7120kb
  • [2024-08-10 14:19:03]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    const int ma = 1e6;
    int s, x;
    cin >> s >> x;
    if (__gcd(s, x) == 1)
    {
        cout << "1\n";
        cout << s << endl;
    }
    else
    {
        vector<int> isp(ma + 1, 1);
        int tmpx = x;
        isp[0] = isp[1] = 0;
        for (int i = 2; i * i <= x; ++i)
        {
            if (x % i) continue;
            while (x % i == 0) x /= i;
            for (int j = 1; i * j <= ma; ++j) isp[i * j] = 0;
        }
        if (x != 1) for (int i = 1; i * x <= ma; ++i) isp[i * x] = 0;
        vector<int> ans;
        if (s % 2)
        {
            ans.push_back(1);
            --s;
        }
        x = tmpx;
        isp[1] = 1;
        for (int i = 1; i <= ma; ++i)
        {
            if (isp[i] == 1)
            {
                if (s - i != 0 && __gcd((int)abs(s - i), x) == 1)
                {
                    ans.push_back(i);
                    ans.push_back(s - i);
                    break;
                }
                if (s + i != 0 && __gcd((int)abs(s + i), x) == 1)
                {
                    ans.push_back(-i);
                    ans.push_back(s + i);
                    break;
                }
            }
        }
        cout << ans.size() << endl;
        for (auto v : ans) cout << v << ' ';
        cout << endl;
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 7056kb

input:

9 6

output:

3
1 1 7 

result:

ok Correct

Test #2:

score: 0
Accepted
time: 2ms
memory: 6928kb

input:

14 34

output:

2
1 13 

result:

ok Correct

Test #3:

score: 0
Accepted
time: 3ms
memory: 7056kb

input:

1000000000 223092870

output:

2
29 999999971 

result:

ok Correct

Test #4:

score: 0
Accepted
time: 2ms
memory: 7120kb

input:

2 1000000000

output:

2
1 1 

result:

ok Correct

Test #5:

score: 0
Accepted
time: 2ms
memory: 6964kb

input:

649557664 933437700

output:

2
-7 649557671 

result:

ok Correct

Test #6:

score: 0
Accepted
time: 2ms
memory: 6912kb

input:

33396678 777360870

output:

2
1 33396677 

result:

ok Correct

Test #7:

score: 0
Accepted
time: 2ms
memory: 7056kb

input:

48205845 903124530

output:

3
1 -23 48205867 

result:

ok Correct

Test #8:

score: 0
Accepted
time: 2ms
memory: 6928kb

input:

251037078 505905400

output:

2
1 251037077 

result:

ok Correct

Test #9:

score: 0
Accepted
time: 2ms
memory: 7056kb

input:

30022920 172746860

output:

2
1 30022919 

result:

ok Correct

Test #10:

score: 0
Accepted
time: 2ms
memory: 6928kb

input:

63639298 808058790

output:

2
-1 63639299 

result:

ok Correct

Test #11:

score: 0
Accepted
time: 3ms
memory: 7120kb

input:

76579017 362768406

output:

3
1 1 76579015 

result:

ok Correct

Test #12:

score: 0
Accepted
time: 2ms
memory: 7056kb

input:

40423669 121437778

output:

3
1 1 40423667 

result:

ok Correct

Test #13:

score: -100
Wrong Answer
time: 2ms
memory: 7052kb

input:

449277309 720915195

output:

3
1 1 449277307 

result:

wrong answer Jury's answer is better than participant's