srm 604 div1 easy
解説ACしたのでメモ
a^nはa進数として考える、そうしたらあとは自明に下の桁からシミュレーションしていけばとける。
この太字にしたところの考え方は大きな知見!!
#include <bits/stdc++.h> #define pb push_back #define REP(i, n) for (signed long long i = 0; i < (n); i++) #define MOD 998244353 #define INF 93193111451418101 #define bitcnt(a) (ll) __builtin_popcount((a)) #define lb(a, b) lower_bound((a).begin(), (a).end(), (b)) #define ub(a, b) upper_bound((a).begin(), (a).end(), (b)) using namespace std; typedef long long ll; typedef pair<ll, ll> P; class PowerOfThree { public: string ableToGet(int x, int y) { x = abs(x); y = abs(y); while (x + y != 0) { if ((x % 3 == 0 && y % 3 == 0) || (x % 3 && y % 3)) { return "Impossible"; } int *calc = &y; if (x % 3) calc = &x; if (*calc % 3 == 1) (*calc)--; else (*calc)++; x /= 3, y /= 3; } return "Possible"; } }; int main() { ll x = 10; ll *a = &x; cout << *a << endl; a++; cout << *a << endl; cout << *a << endl; }