Untitled
unknown
c_cpp
4 years ago
597 B
2
Indexable
#include<bits/stdc++.h> using namespace std; long long returnPower(long long a,long long b){ if(b==0){ return 1; } if(b%2==0){ int half = b/2; int value = returnPower(a,half) % 10; return (value * value) % 10; } else{ return (a * returnPower(a,b-1)) % 10; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; for(int i=0;i<t;i++){ long long a,b; cin >> a >> b; cout << returnPower(a,b) % 10 << endl; } }
Editor is loading...