QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#512536#9167. Coprime Arrayucup-team3723#AC ✓51ms7092kbC++202.8kb2024-08-10 14:49:202024-10-14 07:52:00

Judging History

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

  • [2024-10-14 07:52:00]
  • 管理员手动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:51ms
  • 内存:7092kb
  • [2024-08-11 17:38:28]
  • hack成功,自动添加数据
  • (/hack/775)
  • [2024-08-10 14:49:24]
  • 评测
  • 测评结果:100
  • 用时:51ms
  • 内存:7124kb
  • [2024-08-10 14:49:20]
  • 提交

answer

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

using namespace std;

int main()
{
    const int ma = 1e6;
    int s, x;
    cin >> s >> x;
    vector<int> ans;
    if (__gcd(s, x) == 1)
    {
        ans.push_back(s);
    }
    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;
        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;
                }
            }
        }
        if (ans.empty())
        {
            ans.push_back(1);
            --s;
            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;
                    }
                }
            }
            if (ans.size() == 1) ans.clear();
        }
        if (ans.empty())
        {
            ans.push_back(-1);
            s += 2;
            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;
                    }
                }
            }
            if (ans.size() == 1) ans.clear();
        }
    }
    cout << ans.size() << endl;
    for (auto v : ans) cout << v << ' ';
    cout << endl;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 6984kb

input:

9 6

output:

3
1 1 7 

result:

ok Correct

Test #2:

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

input:

14 34

output:

2
1 13 

result:

ok Correct

Test #3:

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

input:

1000000000 223092870

output:

2
29 999999971 

result:

ok Correct

Test #4:

score: 0
Accepted
time: 1ms
memory: 7088kb

input:

2 1000000000

output:

2
1 1 

result:

ok Correct

Test #5:

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

input:

649557664 933437700

output:

2
-7 649557671 

result:

ok Correct

Test #6:

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

input:

33396678 777360870

output:

2
1 33396677 

result:

ok Correct

Test #7:

score: 0
Accepted
time: 32ms
memory: 7004kb

input:

48205845 903124530

output:

3
1 -23 48205867 

result:

ok Correct

Test #8:

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

input:

251037078 505905400

output:

2
1 251037077 

result:

ok Correct

Test #9:

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

input:

30022920 172746860

output:

2
1 30022919 

result:

ok Correct

Test #10:

score: 0
Accepted
time: 0ms
memory: 6920kb

input:

63639298 808058790

output:

2
-1 63639299 

result:

ok Correct

Test #11:

score: 0
Accepted
time: 37ms
memory: 7012kb

input:

76579017 362768406

output:

3
1 1 76579015 

result:

ok Correct

Test #12:

score: 0
Accepted
time: 51ms
memory: 7092kb

input:

40423669 121437778

output:

3
1 1 40423667 

result:

ok Correct

Test #13:

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

input:

449277309 720915195

output:

2
1 449277308 

result:

ok Correct

Test #14:

score: 0
Accepted
time: 32ms
memory: 6936kb

input:

81665969 919836918

output:

3
1 5 81665963 

result:

ok Correct

Test #15:

score: 0
Accepted
time: 0ms
memory: 6972kb

input:

470578680 280387800

output:

2
1 470578679 

result:

ok Correct

Test #16:

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

input:

58450340 803305503

output:

2
1 58450339 

result:

ok Correct

Test #17:

score: 0
Accepted
time: 34ms
memory: 6920kb

input:

125896113 323676210

output:

3
1 -17 125896129 

result:

ok Correct

Test #18:

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

input:

381905348 434752500

output:

2
1 381905347 

result:

ok Correct

Test #19:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

78916498 653897673

output:

1
78916498 

result:

ok Correct

Test #20:

score: 0
Accepted
time: 32ms
memory: 7084kb

input:

35787885 270845190

output:

3
1 1 35787883 

result:

ok Correct

Extra Test:

score: 0
Extra Test Passed