Advertisement
SorahISA

[NHSPC 2019] B. 完全平方二項係數

Apr 21st, 2020
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. // #pragma GCC target("avx2")
  2. #pragma GCC optimize("O3", "unroll-loops")
  3.  
  4. // #include <bits/extc++.h>
  5. // using namespace __gnu_pbds;
  6.  
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9.  
  10. #define int long long
  11. #define double long double
  12. // template <typename T>
  13. // using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  14. using pii = pair<int, int>;
  15. template<typename T>
  16. using prior = priority_queue<T, vector<T>, greater<T>>;
  17. template<typename T>
  18. using Prior = priority_queue<T>;
  19.  
  20. #define X first
  21. #define Y second
  22. #define ALL(x) (x).begin(), (x).end()
  23. #define eb emplace_back
  24. #define pb push_back
  25.  
  26. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  27. #define RANDOM() random_device __rd; \
  28.                  mt19937 __gen = mt19937(__rd()); \
  29.                  uniform_int_distribution<int> __dis(0, 1); \
  30.                  auto rnd = bind(__dis, __gen);
  31.  
  32. const int INF = 1E18;
  33. const int mod = 1E9 + 7;
  34.  
  35. int32_t main() {
  36.     fastIO();
  37.    
  38.     int t;
  39.     cin >> t;
  40.     while (t--) {
  41.         uint64_t n;
  42.         cin >> n;
  43.        
  44.         int ansX = 1, ansY = 0, baseX = 3, baseY = 2, tmpX, tmpY;
  45.         while (n) {
  46.             if (n & 1) {
  47.                 tmpX = ansX * baseX + 2 * ansY * baseY;
  48.                 tmpY = ansX * baseY + ansY * baseX;
  49.                 ansX = tmpX % mod, ansY = tmpY % mod;
  50.             }
  51.             tmpX = baseX * baseX + 2 * baseY * baseY;
  52.             tmpY = 2 * baseX * baseY;
  53.             baseX = tmpX % mod, baseY = tmpY % mod;
  54.             n >>= 1;
  55.         }
  56.        
  57.         cout << (ansX+1) * (int)(5E8 + 4) % mod << " ";
  58.         cout << ansY * (int)(5E8 + 4) % mod << "\n";
  59.     }
  60.    
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement