QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#711225#5676. Counting Pythagorean TriplesdbaumgAC ✓2ms3684kbC++201.0kb2024-11-05 04:06:452024-11-05 04:06:45

Judging History

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

  • [2024-11-05 04:06:45]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3684kb
  • [2024-11-05 04:06:45]
  • 提交

answer

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

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n;
    cin >> n;
    ll ans1 = 0;
    ll ans2 = 0;
    for (ll a = 1; a < n; a++) {
        for (ll b = a; b < n; b++) {
            if (a * a + b * b == n * n) {
                if (gcd(gcd(a, b), n) == 1) {
                    ans1 += 1;
                } else {
                    ans2 += 1;
                }
            }
        }
    }
    cout << ans1 << " " << ans2 << " ";
    ans1 = 0;
    ans2 = 0;
    for (ll d = 1; d * d <= n * n; d++) {
        if ((n * n) % d == 0) {
            ll d1 = d;
            ll d2 = n * n / d;
            ll c = (d1 + d2) / 2;
            ll b = d2 - c;
            if (b <= 0 || c <= 0 || n * n != c * c - b * b)
                continue;
            if (gcd(gcd(b, c), n) == 1)
                ans1 += 1;
            else
                ans2 += 1;
        }
    }
    cout << ans1 << " " << ans2;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

65

output:

2 2 2 2

result:

ok single line: '2 2 2 2'

Test #2:

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

input:

64

output:

0 0 1 4

result:

ok single line: '0 0 1 4'

Test #3:

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

input:

2023

output:

0 2 2 5

result:

ok single line: '0 2 2 5'

Test #4:

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

input:

1560

output:

0 4 8 59

result:

ok single line: '0 4 8 59'

Test #5:

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

input:

1625

output:

2 8 2 8

result:

ok single line: '2 8 2 8'

Test #6:

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

input:

1888

output:

0 0 2 11

result:

ok single line: '0 0 2 11'

Test #7:

score: 0
Accepted
time: 0ms
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: 3644kb

input:

1950

output:

0 7 0 22

result:

ok single line: '0 7 0 22'

Test #9:

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

input:

2477

output:

1 0 1 0

result:

ok single line: '1 0 1 0'

Test #10:

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

input:

1728

output:

0 0 2 36

result:

ok single line: '0 0 2 36'

Test #11:

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

input:

2249

output:

2 2 2 2

result:

ok single line: '2 2 2 2'

Test #12:

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

input:

2176

output:

0 1 2 17

result:

ok single line: '0 1 2 17'

Test #13:

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

input:

2467

output:

0 0 1 0

result:

ok single line: '0 0 1 0'

Test #14:

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

input:

1898

output:

0 4 0 4

result:

ok single line: '0 4 0 4'

Test #15:

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

input:

2048

output:

0 0 1 9

result:

ok single line: '0 0 1 9'

Test #16:

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

input:

1875

output:

0 4 2 11

result:

ok single line: '0 4 2 11'

Test #17:

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

input:

2187

output:

0 0 1 6

result:

ok single line: '0 0 1 6'

Test #18:

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

input:

2431

output:

0 4 4 9

result:

ok single line: '0 4 4 9'

Test #19:

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

input:

2028

output:

0 2 4 18

result:

ok single line: '0 2 4 18'

Test #20:

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

input:

1105

output:

4 9 4 9

result:

ok single line: '4 9 4 9'

Test #21:

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

input:

2210

output:

0 13 0 13

result:

ok single line: '0 13 0 13'

Test #22:

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

input:

2465

output:

4 9 4 9

result:

ok single line: '4 9 4 9'

Test #23:

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

input:

2187

output:

0 0 1 6

result:

ok single line: '0 0 1 6'