PrimeNumber and countTrailingZeros (Pinely Round 3 (Div. 1 + Div. 2) Problem B)
Sat Dec 23 2023 16:02:58 GMT+0000 (Coordinated Universal Time)
Saved by
@coderworld
#include <bits/stdc++.h>
using namespace std;
#define sr srand(time(0));
#define ra(l, h) (rand() % ((h)-(l)+1) + (l))
#define sync { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
#define ll long long int
#define vi vector<int>
#define fn(n) for(int i = 0; i < n; i++)
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rfr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define all(a) a.begin(), a.end()
#define tt int test; cin >> test; while(test--)
#define ff first
#define ss second
#define en cout<< "\n"
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
int countTrailingZeros(int num) {
int count = 0;
while (num % 10 == 0) {
count++;
num /= 10;
}
return count;
}
bool isPrime(int n) {
if (n <= 1) {
return false;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main() {
sync
tt {
int n;
cin >> n;
vi v(n);
fn(n) cin >> v[i];
int commonZeros = countTrailingZeros(v[0]);
for (int i = 1; i < n; i++) {
int trailingZeros = countTrailingZeros(v[i]);
commonZeros = min(commonZeros, trailingZeros);
}
// cout << commonZeros << " ";
int ans = 0;
set<int> rem;
for(ll k=2; k<pow(10,18); k++){
if( isPrime(k) ) {
k = k * pow(10, commonZeros);
for(int i=0; i<n; i++){
rem.insert(v[i]%k);
}
if(rem.size() == 2){
ans = k;
break;
}
}
}
cout << ans << endl;
}
return 0;
}
content_copyCOPY
Comments