Advertisement
Dang_Quan_10_Tin

PYTHAGORE TS10 PTNK 2018-2019

Jan 6th, 2022
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #define task "PYTHAGORE"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. using ll = long long;
  10. using ld = long double;
  11.  
  12. constexpr int N = 5e3 + 5;
  13. int cnt[N];
  14.  
  15. void Prepare()
  16. {
  17.     for (int a = 1; a < N; ++a)
  18.         for (int b = a + 1; a + b < N; ++b)
  19.         {
  20.             int c = sqrt(a * a + b * b);
  21.             if (c * c == a * a + b * b && a + b + c < N)
  22.                 ++cnt[a + b + c];
  23.         }
  24. }
  25.  
  26. void Solve()
  27. {
  28.     int t;
  29.     cin >> t;
  30.     while (t--)
  31.     {
  32.         int p;
  33.         cin >> p;
  34.         cout << cnt[p] << "\n";
  35.     }
  36. }
  37.  
  38. int32_t main()
  39. {
  40.     ios::sync_with_stdio(0);
  41.     cin.tie(0);
  42.     cout.tie(0);
  43.     if (fopen(task ".INP", "r"))
  44.     {
  45.         freopen(task ".INP", "r", stdin);
  46.         freopen(task ".OUT", "w", stdout);
  47.     }
  48.  
  49.     Prepare();
  50.     Solve();
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement