QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#670756#5676. Counting Pythagorean Triplesrand123AC ✓170ms3788kbC++201.5kb2024-10-24 00:23:452024-10-24 00:23:45

Judging History

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

  • [2024-10-24 00:23:45]
  • 评测
  • 测评结果:AC
  • 用时:170ms
  • 内存:3788kb
  • [2024-10-24 00:23:45]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define yes "YES"
#define no "NO"
#define ll long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define MOD2 998244353
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> 
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(int cas){
    ll n;
    cin>>n;
    ll squared = n*n, ans1 = 0, ans2 = 0;
    for (ll i = 1; i < n; i++){
        ll diff = squared - i*i;
        ll s = static_cast<ll> (sqrtl(diff));
        if (s*s==diff && s>=i){
            if (__gcd(s,i)==1 && __gcd(i,n)==1 && __gcd(s,n)==1){
                ans1++;
            }
            else{
                ans2++;
            }
        }
    }
    cout<<ans1<<" "<<ans2<<" ";
    ll ans3 = 0, ans4 = 0;
    for (ll i = n+1; i <= static_cast<ll> (4e7); i++){
        ll diff = i*i - squared;
        ll s = static_cast<ll> (sqrtl(diff));
        if (s*s==diff){
            if (__gcd(s,i)==1 && __gcd(i,n)==1 && __gcd(s,n)==1){
                ans3++;
            }
            else{
                ans4++;
            }
        }
    }
    cout<<ans3<<" "<<ans4<<endl;
    
}
int main(){
    int t=1;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //cin>>t;
    for (int i = 1; i<=t; i++){
        solve(i);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 170ms
memory: 3556kb

input:

65

output:

2 2 2 2

result:

ok single line: '2 2 2 2'

Test #2:

score: 0
Accepted
time: 169ms
memory: 3596kb

input:

64

output:

0 0 1 4

result:

ok single line: '0 0 1 4'

Test #3:

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

input:

2023

output:

0 2 2 5

result:

ok single line: '0 2 2 5'

Test #4:

score: 0
Accepted
time: 170ms
memory: 3660kb

input:

1560

output:

0 4 8 59

result:

ok single line: '0 4 8 59'

Test #5:

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

input:

1625

output:

2 8 2 8

result:

ok single line: '2 8 2 8'

Test #6:

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

input:

1888

output:

0 0 2 11

result:

ok single line: '0 0 2 11'

Test #7:

score: 0
Accepted
time: 170ms
memory: 3704kb

input:

2125

output:

2 8 2 8

result:

ok single line: '2 8 2 8'

Test #8:

score: 0
Accepted
time: 164ms
memory: 3504kb

input:

1950

output:

0 7 0 22

result:

ok single line: '0 7 0 22'

Test #9:

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

input:

2477

output:

1 0 1 0

result:

ok single line: '1 0 1 0'

Test #10:

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

input:

1728

output:

0 0 2 36

result:

ok single line: '0 0 2 36'

Test #11:

score: 0
Accepted
time: 170ms
memory: 3504kb

input:

2249

output:

2 2 2 2

result:

ok single line: '2 2 2 2'

Test #12:

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

input:

2176

output:

0 1 2 17

result:

ok single line: '0 1 2 17'

Test #13:

score: 0
Accepted
time: 169ms
memory: 3744kb

input:

2467

output:

0 0 1 0

result:

ok single line: '0 0 1 0'

Test #14:

score: 0
Accepted
time: 169ms
memory: 3788kb

input:

1898

output:

0 4 0 4

result:

ok single line: '0 4 0 4'

Test #15:

score: 0
Accepted
time: 170ms
memory: 3660kb

input:

2048

output:

0 0 1 9

result:

ok single line: '0 0 1 9'

Test #16:

score: 0
Accepted
time: 170ms
memory: 3664kb

input:

1875

output:

0 4 2 11

result:

ok single line: '0 4 2 11'

Test #17:

score: 0
Accepted
time: 170ms
memory: 3696kb

input:

2187

output:

0 0 1 6

result:

ok single line: '0 0 1 6'

Test #18:

score: 0
Accepted
time: 170ms
memory: 3748kb

input:

2431

output:

0 4 4 9

result:

ok single line: '0 4 4 9'

Test #19:

score: 0
Accepted
time: 165ms
memory: 3740kb

input:

2028

output:

0 2 4 18

result:

ok single line: '0 2 4 18'

Test #20:

score: 0
Accepted
time: 169ms
memory: 3544kb

input:

1105

output:

4 9 4 9

result:

ok single line: '4 9 4 9'

Test #21:

score: 0
Accepted
time: 170ms
memory: 3656kb

input:

2210

output:

0 13 0 13

result:

ok single line: '0 13 0 13'

Test #22:

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

input:

2465

output:

4 9 4 9

result:

ok single line: '4 9 4 9'

Test #23:

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

input:

2187

output:

0 0 1 6

result:

ok single line: '0 0 1 6'