Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef long long ll;
- ll solve(ll x, int days) {
- for(int i = 1; i <= days; i++) {
- if(i % 2 == 1) {
- x += 2;
- }
- else {
- x -= 1;
- }
- if(x % 4 == 0) {
- x *= -1;
- }
- }
- return x;
- }
- int main() {
- ll n, x;
- cin >> n >> x;
- ll a = solve(x, 8);
- ll b = solve(a, 8);
- ll d1 = a - x, d2 = b - a;
- if(d1 == d2) {
- ll f = n / 8, rem = n % 8;
- cout << solve(x, rem) + f * (solve(a, rem) - solve(x, rem)) << endl;;
- }
- else {
- cout << solve(x, n % 16) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment