artemgf

Квадратная страна fast

Jun 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #pragma once
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #define _USE_MATH_DEFINES
  4. #include <iostream>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <stdio.h>
  11. #include <cmath>
  12. #include <math.h>
  13. #include <queue>
  14. #include <stack>
  15. #include <climits>
  16. #include <deque>
  17. #include <ctime>
  18. #include <iomanip>
  19. #include <bitset>
  20. #include <unordered_map>
  21. #include <unordered_set>
  22.  
  23. using namespace std;
  24.  
  25. typedef long long ll;
  26. typedef unsigned long long ull;
  27. typedef unsigned int ui;
  28.  
  29. #define mh() make_heap()
  30. #define poph() pop_heap()
  31. #define pushh() push_heap()
  32. #define sor(n) n.begin(), n.end()
  33. #define rsor(n) n.rbegin(), n.rend()
  34. #define mp make_pair
  35. #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
  36. #define p(T) pair<T,T>
  37. #define toch(x) cout.precision(x), cout.setf(ios::fixed)
  38. #define znac(l) abs(l)/l
  39. #define IOS ios::sync_with_stdio(false)
  40. #define IOSB cin.tie(0), cout.tie(0);
  41. const ll ok = ll(1e9 + 7);
  42.  
  43. bool chk2(ll n, ll k)
  44. {
  45.     for (ll i=1, j=k; i <= j; i++)
  46.     {
  47.         while (i*i + j*j > n)j--;
  48.         if (i*i + j*j == n)return 1;
  49.     }
  50.     return 0;
  51. }
  52. bool chk4(ll n)
  53. {
  54.     ll p = 1;
  55.     for (ll i = 0; i <= 50; i += 2)
  56.     {
  57.         if (n%p != 0)
  58.             break;
  59.         if (((n / p) - 7) % 8 == 0)
  60.             return 1;
  61.         p <<= 2;
  62.     }
  63.     return 0;
  64. }
  65. int main()
  66. {
  67.     IOSB;
  68.     IOS;
  69. #ifdef TheCompiler
  70.     files;
  71. #endif
  72.     ll n, k;
  73.     cin >> n;
  74.     k = sqrt(n);
  75.     if (k*k == n)
  76.     {
  77.         cout << 1 << endl;
  78.         return 0;
  79.     }
  80.     if (chk2(n, k))
  81.     {
  82.         cout << 2 << endl;
  83.         return 0;
  84.     }
  85.     if (chk4(n))
  86.     {
  87.         cout << 4 << endl;
  88.         return 0;
  89.     }
  90.     cout << 3;
  91.  
  92.     return 0;
  93. }
Add Comment
Please, Sign In to add comment