Advertisement
Dang_Quan_10_Tin

BITWEIGHT

May 26th, 2022
487
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define task "BITWEIGHT"
  2. #include <iostream>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. constexpr int N = 1e5 + 5;
  11. constexpr int mod = 1e9 + 7;
  12. string s;
  13. int n;
  14. ll m;
  15.  
  16. void Read()
  17. {
  18.     cin >> s;
  19. }
  20.  
  21. ll Pow(ll a, ll b)
  22. {
  23.     ll ans(1);
  24.     for (; b; b >>= 1)
  25.     {
  26.         if (b & 1)
  27.             ans = ans * a % mod;
  28.         a = a * a % mod;
  29.     }
  30.  
  31.     return ans;
  32. }
  33.  
  34. void Solve()
  35. {
  36.     n = 0;
  37.     m = 0;
  38.     for (auto i : s)
  39.     {
  40.         n = (n * 10 + i - '0') % (mod - 1);
  41.         m = (m * 10 + i - '0') % mod;
  42.     }
  43.  
  44.     cout << Pow(2, (n - 1 + mod - 1) % (mod -1)) * m % mod << "\n";
  45. }
  46.  
  47. int32_t main()
  48. {
  49.     ios_base::sync_with_stdio(0);
  50.     cin.tie(0);
  51.     cout.tie(0);
  52.  
  53.     if (fopen(task ".INP", "r"))
  54.     {
  55.         freopen(task ".INP", "r", stdin);
  56.         freopen(task ".OUT", "w", stdout);
  57.     }
  58.  
  59.     int t;
  60.     for (cin >> t; t--;)
  61.     {
  62.         Read();
  63.         Solve();
  64.     }
  65. }
Advertisement
RAW Paste Data Copied
Advertisement