C++ Daily Practice – Olympiad Basics 2024: Example 4.10 Last Two Digits

C++ Daily Practice - Olympiad Basics 2024: Example 4.10 Last Two Digits

2024: Example 4.10 Last Two Digits

Time Limit: 1000 ms Memory Limit: 65536 KB【Problem Description】What are the last two digits of the product of n instances of 1992?

【Input】Input n.

【Output】The last two digits as described in the problem.

【Sample Input】3【Sample Output】88【Hint】【Data Range】For all data: n<2000.

Problem Analysis:The product of n instances of 1992 can be calculated by multiplying 1992 n times, considering the large data issue, use long long type; The last two digits: directly %100

Prerequisite Knowledge:(a*b*c)%p=(a%p*b%p*c%p)%p

/**/
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long sum = 1;
    for(int i = 1; i <= n; i++){
        sum *= 1992;
        sum = sum % 100;
    }
    cout << sum;
    return 0;
}

This problem is the same as the previous one《C++ Daily Practice – Olympiad Basics 1084: Last Digits of Power》.

C++ Daily Practice - Olympiad Basics 2024: Example 4.10 Last Two Digits
C++ Daily Practice - Olympiad Basics 2024: Example 4.10 Last Two Digits
Previous Issues Review
C++ Daily Practice – Olympiad Basics 1084: Last Digits of Power
C++ Daily Practice – Olympiad Basics 1069: Exponentiation Calculation (Fast Exponentiation)
C++ Daily Practice - Olympiad Basics 2024: Example 4.10 Last Two Digits

Leave a Comment