Josif_tepe

Untitled

Mar 4th, 2026
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. using namespace std;
  5. typedef long long ll;
  6.  
  7. ll solve(ll x, ll days) {
  8.     for(ll i = 1; i <= days; i++) {
  9.         if(i % 2 == 1) {
  10.             x += 2;
  11.         }
  12.         else {
  13.             x--;
  14.         }
  15.         if(x % 4 == 0) {
  16.             x = -x;
  17.         }
  18.     }
  19.     return x;
  20. }
  21. int main() {
  22.     ios_base::sync_with_stdio(false);
  23.     ll n, x;
  24.     cin >> n >> x;
  25.    
  26.     ll F = n / 8;
  27.     ll rem = n % 8;
  28.    
  29.     ll a = solve(x, 8);
  30.     ll d = solve(a, rem) - solve(x, rem);
  31.    
  32.     cout << solve(x, rem) + F * d << endl;
  33.    
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment