QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#155174#5676. Counting Pythagorean Triplesrgnerdplayer#AC ✓5ms3564kbC++201.3kb2023-09-01 13:02:542023-09-01 13:02:55

Judging History

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

  • [2023-09-01 13:02:55]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:3564kb
  • [2023-09-01 13:02:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    
    auto solve = [&]() {
        int c;
        cin >> c;

        auto primitive = [&](int a, int b, int c) {
            return gcd(a, b) == 1 && gcd(b, c) == 1 && gcd(c, a) == 1;
        };

        int ans1 = 0, ans2 = 0;
        for (int a = 1; a < c; a++) {
            for (int b = a; b < c; b++) {
                if (a * a + b * b == c * c) {
                    if (primitive(a, b, c)) {
                        ans1++;
                    } else {
                        ans2++;
                    }
                }
            }
        }

        cout << ans1 << ' ' << ans2 << ' ';

        ans1 = ans2 = 0;

        for (int x = 1; x < c; x++) {
            if (c * c % x == 0) {
                int y = c * c / x;
                if (x % 2 != y % 2) {
                    continue;
                }
                int a = (x + y) / 2, b = (y - x) / 2;
                if (primitive(c, b, a)) {
                    ans1++;
                } else {
                    ans2++;
                }
            }
        }

        cout << ans1 << ' ' << ans2 << '\n';
    };

    solve();

    return 0;
}


詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3428kb

input:

65

output:

2 2 2 2

result:

ok single line: '2 2 2 2'

Test #2:

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

input:

64

output:

0 0 1 4

result:

ok single line: '0 0 1 4'

Test #3:

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

input:

2023

output:

0 2 2 5

result:

ok single line: '0 2 2 5'

Test #4:

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

input:

1560

output:

0 4 8 59

result:

ok single line: '0 4 8 59'

Test #5:

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

input:

1625

output:

2 8 2 8

result:

ok single line: '2 8 2 8'

Test #6:

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

input:

1888

output:

0 0 2 11

result:

ok single line: '0 0 2 11'

Test #7:

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

input:

2125

output:

2 8 2 8

result:

ok single line: '2 8 2 8'

Test #8:

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

input:

1950

output:

0 7 0 22

result:

ok single line: '0 7 0 22'

Test #9:

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

input:

2477

output:

1 0 1 0

result:

ok single line: '1 0 1 0'

Test #10:

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

input:

1728

output:

0 0 2 36

result:

ok single line: '0 0 2 36'

Test #11:

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

input:

2249

output:

2 2 2 2

result:

ok single line: '2 2 2 2'

Test #12:

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

input:

2176

output:

0 1 2 17

result:

ok single line: '0 1 2 17'

Test #13:

score: 0
Accepted
time: 5ms
memory: 3396kb

input:

2467

output:

0 0 1 0

result:

ok single line: '0 0 1 0'

Test #14:

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

input:

1898

output:

0 4 0 4

result:

ok single line: '0 4 0 4'

Test #15:

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

input:

2048

output:

0 0 1 9

result:

ok single line: '0 0 1 9'

Test #16:

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

input:

1875

output:

0 4 2 11

result:

ok single line: '0 4 2 11'

Test #17:

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

input:

2187

output:

0 0 1 6

result:

ok single line: '0 0 1 6'

Test #18:

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

input:

2431

output:

0 4 4 9

result:

ok single line: '0 4 4 9'

Test #19:

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

input:

2028

output:

0 2 4 18

result:

ok single line: '0 2 4 18'

Test #20:

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

input:

1105

output:

4 9 4 9

result:

ok single line: '4 9 4 9'

Test #21:

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

input:

2210

output:

0 13 0 13

result:

ok single line: '0 13 0 13'

Test #22:

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

input:

2465

output:

4 9 4 9

result:

ok single line: '4 9 4 9'

Test #23:

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

input:

2187

output:

0 0 1 6

result:

ok single line: '0 0 1 6'