제출 #1247705

#제출 시각아이디문제언어결과실행 시간메모리
1247705piedavBrunhilda’s Birthday (BOI13_brunhilda)C++20
41.43 / 100
1099 ms1212 KiB
#include <iostream>
#include <vector>
using namespace std;

#define int long long

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int m, q;
    cin >> m >> q;
    vector<int> p (m);
    //quickly check if the product > 10^7
    int product = 1;
    for(int i = 0; i < m; ++i) {
        cin >> p[i];
        if(product <= 10000000) product *= p[i];
    }
    int n;
    for(int i = 0; i < q; ++i) {
        cin >> n;
        if(n >= product) {
            cout << "oo\n";
            continue;
        }
        //loop time
        int counter = 0;
        while(n >= p[m-1]) {
            counter++;
            //find the maximum prime
            int newn = n;
            for(int i = m-1; i >= 0; --i) {
                if(n % p[i] != 0) {
                    newn = min(newn, n/p[i]*p[i]);
                }
            }
            n = newn;
        }
        cout << counter+1 << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...