Advertisement
SorahISA

[TOI 2020 0th] C. 銀河捷運

Apr 20th, 2020
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 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. void solve() {
  36.     int M, a, b, x1, y1, x2, y2, x3, y3, m, k;
  37.     cin >> M >> a >> b >> x1 >> y1 >> x2 >> y2;
  38.    
  39.     auto fastpow = [=](int base, int exp, int ans = 1) {
  40.         while (exp) {
  41.             if (exp & 1) ans = ans * base % M;
  42.             base = base * base % M, exp >>= 1;
  43.         }
  44.         return ans;
  45.     };
  46.    
  47.     auto ADD = [=](int _a, int _b) {
  48.         return ((_a + _b) % M + M) % M;
  49.     };
  50.    
  51.     auto SUB = [=](int _a, int _b) {
  52.         return ((_a - _b) % M + M) % M;
  53.     };
  54.    
  55.     m = SUB(y2, y1) * fastpow(SUB(x2, x1), M-2) % M;
  56.     k = SUB(y1, m * x1);
  57.    
  58.     x3 = SUB(m * m, x1 + x2);
  59.     y3 = ADD(m * x3, k);
  60.    
  61.     cout << x3 << " " << y3 << "\n";
  62. }
  63.  
  64. int32_t main() {
  65.     fastIO();
  66.    
  67.     int t;
  68.     cin >> t;
  69.     while (t--) solve();
  70.    
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement