-
Notifications
You must be signed in to change notification settings - Fork 1
/
right_most_non_digit_number.cpp
55 lines (52 loc) · 1.07 KB
/
right_most_non_digit_number.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
using namespace std;
int getFiveCount(long long* arr, int n){
int fiveCount=0;
long long temp;
for(int i=0;i<n;i++){
temp= arr[i];
while(temp && !(temp%5)){
fiveCount++;
temp/=5;
}
arr[i]= temp;
}
return fiveCount;
}
long long eliminate2(long long* arr, int n, int fiveCount){
long long temp;
for(int i=0;i<n;i++){
temp=arr[i];
while(fiveCount && temp && !(temp&1)){
temp>>=1;
fiveCount--;
}
arr[i]=temp;
if(!fiveCount)
break;
}
return fiveCount;
}
int main()
{
//code
int t,n;
long long arr[102];
cin >> t;
while(t--){
cin >> n;
for(int i=0;i<n;i++)
cin >> arr[i];
long long mod=1;
int fiveCount= getFiveCount(arr,n);
int fiveRemains= eliminate2(arr,n,fiveCount);
if(fiveRemains)
mod=5;
for(int i=0;i<n;i++)
mod=(mod*(arr[i]%10))%10;
if(mod==0)
mod=-1;
cout << mod <<endl;
}
return 0;
}