TEXT   89

Untitled

Guest on 14th May 2022 03:29:33 PM

  1. /* Goal to be an candidate master*/
  2. #include<bits/stdc++.h>
  3. #include<tuple>
  4. using namespace std;
  5. #define ll long long int
  6. #define ull unsigned long long int
  7. #define dd double
  8. #define endl "\n"
  9. #define pb push_back
  10. #define all(v) v.begin(),v.end()
  11. // #define mp make_pair
  12. #define fi first
  13. #define se second
  14. #define vll vector<ll>
  15. #define pll pair<ll,ll>
  16. #define fo(i,n) for(int i=0;i<n;i++)
  17. #define fo1(i,n) for(int i=1;i<=n;i++)
  18. #define fore(i, l, r) for(int i = int(l); i < int(r); i++)
  19. #define min3(a,b,c) min(a,min(b,c))
  20. #define pi 3.14159265358979323846264338
  21. #define e(v) v.empty()
  22. #define bscount(x) __builtin_popcountll(x)
  23. #define sz(x) (int)(x).size()
  24. ll mod = 100000000007;
  25. ll n, k, t, m, q, flag = 0;
  26. ll power(ll a, ll b) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;}
  27. ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); }
  28. ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
  29. ll min(ll a, ll b) {if (a > b)return b; else return a;}
  30. ll max(ll a, ll b) {if (a > b)return a; else return b;}
  31. ll ceil_div(ll a, ll b) {return a % b == 0 ? a / b : a / b + 1;}
  32.  
  33.  
  34. bool isPowerOfTwo(ll n)
  35. {
  36.   if (n == 0)
  37.     return false;
  38.  
  39.   return (ceil(log2(n)) == floor(log2(n)));
  40. }
  41.  
  42. void solve() {
  43.   ll n; cin >> n;
  44.   ll inc, dec; cin >> dec >> inc;
  45.   vll v = {3, 5, 7};
  46.   ll ans = 1e18 + 1;
  47.  
  48.   for (int i = 0; i < 3; i++)
  49.   {
  50.     for (int j = i + 1; j < 3; j++)
  51.     {
  52.       for (int p1 = 1; p1 <= 20; p1++)
  53.       {
  54.         for (int p2 = 1; p2 <= 20; p2++)
  55.         {
  56.           ll num1 = 1, num2 = 1;
  57.           fo1(k, p1)num1 *= v[i];
  58.           fo1(k, p2)num2 *= v[j];
  59.  
  60.           ll sum = num1 + num2;
  61.           // cout << sum << endl;
  62.           if (sum > n)
  63.           {
  64.             // cout << sum << " " << n << endl;
  65.             ll cost = (sum - n) * inc;
  66.             if (cost >= 0)
  67.               ans = min(ans, cost);
  68.           }
  69.           else
  70.           {
  71.             ll cost = (n - sum) * dec;
  72.             if (cost >= 0)
  73.               ans = min(ans, cost);
  74.           }
  75.  
  76.         }
  77.       }
  78.     }
  79.   }
  80.  
  81.   cout << ans << endl;
  82.  
  83.  
  84. }
  85.  
  86. int main()
  87. {
  88. #ifndef ONLINE_JUDGE
  89.   // for getting input from input.txt
  90.   freopen("input.txt", "r", stdin);
  91.   // for writing output to output.txt
  92.   freopen("o.txt", "w", stdout);
  93. #endif
  94.   int T;
  95.   T = 1;
  96.   ios_base::sync_with_stdio(0);
  97.   cin.tie(0);
  98.   cin >> T;
  99.   // precompute();
  100.   for (int i = 1; i <= T; i++)
  101.   {
  102.     // cout<<"Case #"<<i<<": ";
  103.     solve();
  104.   }
  105.   cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  106. }

Raw Paste


Login or Register to edit or fork this paste. It's free.