Cod sursa(job #3233329)

Utilizator MirceaDonciuLicentaLicenta Mircea Donciu MirceaDonciuLicenta Data 2 iunie 2024 23:31:18
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#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;
}