Josif_tepe

Untitled

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