Ingredients that may Harm You

시간 제한1초메모리 제한1024 MB

요약
음식 번호들의 중복집합과 알레르기 번호가 주어질 때, 각 알레르기 번호와 서로소인 곱을 갖는 요리(음식의 부분 중복집합)의 수를 1e9+7로 나눈 나머지로 구한다.
난이도

보통10점 중 7점

유형
정수론, 조합론, 비트 연산, 수학
정답자
아직 제출이 없습니다

문제

In Nlogonia, foods are identified by numbers. Prime numbers identify the basic ingredients, and the number that identifies each food is given by the product of the numbers associated with the ingredients that compose it, respecting multiplicities. For example, a food with the number 1212 contains two units of the ingredient 22, and one unit of the ingredient 33, since 12=2⋅2⋅312 = 2 \cdot 2 \cdot 3.

You live in Nlogonia, and you own a self-service restaurant, that is, where people assemble their own dishes with the food available in the restaurant. You are expecting to serve QQ people in your restaurant today.

Each person has a set of allergies, which are identified by an integer in the same way: each prime number that divides the person’s number indicates that he or she is allergic to the ingredient associated with that prime number.

Given the numbers associated with each food item in your restaurant, calculate, for each of the QQ people, how many different dishes she can assemble so that there is no ingredient in the dish to which she is allergic.

입력

The first line of the input contains an integer NN (1≤N≤1051 ≤ N ≤ 10^5), the number of foods in your restaurant. The next line contains the numbers associated with each food V_iV\_i (1≤V_i≤1061 ≤ V\_i ≤ 10^6). The next line contains an integer QQ (1≤Q≤1051 ≤ Q ≤ 10^5), the number of people who will eat at your restaurant. QQ lines follow; the ii-th of them contains a number X_iX\_i (1≤X_i≤1061 ≤ X\_i ≤ 10^6), the number representing the allergies of person ii.

출력

For each of the QQ people, print a number: the number of dishes that can be assembled with the restaurant’s ingredients, so that none of the ingredients to which the person is allergic are present. Since the answer may be very large, print the remainder when dividing it by 109+710^9 + 7.

예제1

  1. 예제 1

    입력
    6
    1 2 3 4 5 6
    4
    1
    2
    4
    6
    
    예상 출력
    64
    8
    8
    4