Spoj LASTDIG - The last digit Solution
Algorithm:https://www.geeksforgeeks.org/find-last-digit-of-ab-for-large-numbers/
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- long long a,b,r,tm;
- cin>>a>>b;
- if(b==0&&a>0)
- r=1;
- else if(a==0&&b>0)
- r=0;
- else
- {
- if(b%4==0)
- b=4;
- else
- b=b%4;
- r=tm%10;
- }
- cout<<r<<endl;
- }
- }
No comments