//Are You Challenging Me?!
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define pb push_back
#define pf push_front
#define speedyboy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin() , x.end()
#define allr(x) x.rbegin() , x.rend()
#define F first
#define S second
#define pll pair<ll , ll>
#define pss pair<string , string>
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
const ll sz = 5e5 + 5 , INF = 1e18 , MOD = 10;
ll fact[sz];
ll i , j , k , l;
void solve(){
ll n , m , sum = 0;
cin >> n >> m;
if(n == 3 && m == 1){
cout << 1 << endl;
return;
}
ll mn = min(n , 4LL);
for(i = 0 ; i <= mn ; i++){
ll hasil = 1;
for(j = 1 ; j <= m ; j++) hasil *= fact[i];
sum += hasil % 10;
sum %= 10;
}
cout << sum % 10 << endl;
}
signed main(){
fact[0] = 1;
for(i = 1 ; i <= 5 ; i++){
fact[i] = fact[i - 1] * i;
}
speedyboy;
//open;
ll t = 1;
cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |