Pagini recente » Cod sursa (job #2101008) | Cod sursa (job #2418497) | Cod sursa (job #1677673) | Cod sursa (job #2446127) | Cod sursa (job #3233329)
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;
// Function to check if N can be expressed as 2^a * 3^b * 5^c * 7^d * 11^e
bool isValidNumber(long long N) {
if (N == 0) return false;
vector<int> primes = {2, 3, 5, 7, 11};
for (int prime : primes) {
while (N % prime == 0) {
N /= prime;
}
}
return N == 1;
}
int main() {
ifstream infile("dtcsu.in");
ofstream outfile("dtcsu.out");
// Read all the numbers of the form 2^a * 3^b * 5^c * 7^d * 11^e
vector<long long> validNumbers;
long long number;
while (infile >> number) {
validNumbers.push_back(number);
}
// Read the number of queries Q
int Q;
infile >> Q;
// Process each query
int countValid = 0;
while (Q--) {
long long query;
infile >> query;
if (isValidNumber(query)) {
countValid++;
}
}
outfile << countValid << endl;
infile.close();
outfile.close();
return 0;
}