[ Codeforces ] 742A: Arpa’s hard exam and Mehrdad’s naive cheat | C++

Поделиться
HTML-код
  • Опубликовано: 18 янв 2025

Комментарии • 2

  • @LeekCodeDev
    @LeekCodeDev  4 дня назад +1

    To solve this problem, I realized the pattern that we only care about multiples of 8, since that ones digit will determine the last digit in the exponent value. If you repeat the process for the first few times, you will see that the pattern goes from numbers ending with 8, 4, 2, 6, and 8, which then the cycle repeats itself. Therefore all we need to know is how many times n modulo 4 is , which will get us the placement in the premade vector. If it ends up being 0 mod, then we need to take the last value of the array, and to find the location of the vector index for everything else, we need to subtract 1 from our modulus to account for the fact that our vector is 0-indexed.

  • @LeekCodeDev
    @LeekCodeDev  4 дня назад +1

    Source Code:
    #include
    using namespace std;
    #define fastread() { ios::sync_with_stdio(0);cin.tie(0);}
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    int main(){
    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fastread();
    int n;
    cin >> n;
    vector arr = {8,4,2,6};
    int remainder = n % 4;
    if(n == 0) cout