Skip to content

Instantly share code, notes, and snippets.

@maifeeulasad
Created December 9, 2018 11:29
Show Gist options
  • Save maifeeulasad/4beb98a8e512113fe622a7a0bd277657 to your computer and use it in GitHub Desktop.
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
#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