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

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. int main()
    4. {
    5. int t;
    6. cin>>t;
    7. while(t--)
    8. {
    9. long long a,b,r,tm;
    10. cin>>a>>b;
    11. if(b==0&&a>0)
    12. r=1;
    13. else if(a==0&&b>0)
    14. r=0;
    15. else
    16. {
    17. if(b%4==0)
    18. b=4;
    19. else
    20. b=b%4;
    21. tm=pow(a,b);
    22. r=tm%10;
    23. }
    24. cout<<r<<endl;
    25. }
    26. }

    No comments

    Most View Post

    Recent post

    RESTful APIs with CRUD Operations in Laravel 12| (2025)

      RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

    Powered by Blogger.