Created
December 9, 2018 11:29
-
-
Save maifeeulasad/4beb98a8e512113fe622a7a0bd277657 to your computer and use it in GitHub Desktop.
find last 4 digit of (x^y) --- x and y are long long
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int main() | |
{ | |
long long pow=1; | |
long long n=1; | |
while(cin >> n >> pow && pow && n) | |
{ | |
long long res=1; | |
for(long long i=0; i<pow; i++) | |
{ | |
res*=n; | |
res=res%10000; /// 10000 - 4 zero for last four digits | |
///for 5 digits use 100000 | |
} | |
cout << res << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment