CF1866B.Battling with Numbers

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

On the trip to campus during the mid semester exam period, Chaneka thinks of two positive integers XX and YY . Since the two integers can be very big, both are represented using their prime factorisations, such that:

  • X=A1B1×A2B2××ANBNX=A_1^{B_1}\times A_2^{B_2}\times\ldots\times A_N^{B_N} (each AiA_i is prime, each BiB_i is positive, and A1<A2<<ANA_1<A_2<\ldots<A_N )
  • Y=C1D1×C2D2××CMDMY=C_1^{D_1}\times C_2^{D_2}\times\ldots\times C_M^{D_M} (each CjC_j is prime, each DjD_j is positive, and C1<C2<<CMC_1<C_2<\ldots<C_M )

Chaneka ponders about these two integers for too long throughout the trip, so Chaneka's friend commands her "Gece, deh!" (move fast) in order to not be late for the exam.

Because of that command, Chaneka comes up with a problem, how many pairs of positive integers pp and qq such that LCM(p,q)=X\text{LCM}(p, q) = X and GCD(p,q)=Y\text{GCD}(p, q) = Y . Since the answer can be very big, output the answer modulo 998244353998\,244\,353 .

Notes:

  • LCM(p,q)\text{LCM}(p, q) is the smallest positive integer that is simultaneously divisible by pp and qq .
  • GCD(p,q)\text{GCD}(p, q) is the biggest positive integer that simultaneously divides pp and qq .

输入格式

The first line contains a single integer NN ( 1N1051 \leq N \leq 10^5 ) — the number of distinct primes in the prime factorisation of XX .

The second line contains NN integers A1,A2,A3,,ANA_1, A_2, A_3, \ldots, A_N ( 2A1<A2<<AN21062 \leq A_1 < A_2 < \ldots < A_N \leq 2 \cdot 10^6 ; each AiA_i is prime) — the primes in the prime factorisation of XX .

The third line contains NN integers B1,B2,B3,,BNB_1, B_2, B_3, \ldots, B_N ( 1Bi1051 \leq B_i \leq 10^5 ) — the exponents in the prime factorisation of XX .

The fourth line contains a single integer MM ( 1M1051 \leq M \leq 10^5 ) — the number of distinct primes in the prime factorisation of YY .

The fifth line contains MM integers C1,C2,C3,,CMC_1, C_2, C_3, \ldots, C_M ( 2C1<C2<<CM21062 \leq C_1 < C_2 < \ldots < C_M \leq 2 \cdot 10^6 ; each CjC_j is prime) — the primes in the prime factorisation of YY .

The sixth line contains MM integers D1,D2,D3,,DMD_1, D_2, D_3, \ldots, D_M ( 1Dj1051 \leq D_j \leq 10^5 ) — the exponents in the prime factorisation of YY .

输出格式

An integer representing the number of pairs of positive integers pp and qq such that LCM(p,q)=X\text{LCM}(p, q) = X and GCD(p,q)=Y\text{GCD}(p, q) = Y , modulo 998244353998\,244\,353 .

输入输出样例

  • 输入#1

    4
    2 3 5 7
    2 1 1 2
    2
    3 7
    1 1

    输出#1

    8
  • 输入#2

    2
    1299721 1999993
    100000 265
    2
    1299721 1999993
    100000 265

    输出#2

    1
  • 输入#3

    2
    2 5
    1 1
    2
    2 3
    1 1

    输出#3

    0

说明/提示

In the first example, the integers are as follows:

  • X=22×31×51×72=2940X=2^2\times3^1\times5^1\times7^2=2940
  • Y=31×71=21Y=3^1\times7^1=21

The following are all possible pairs of pp and qq :

  • p=21p=21 , q=2940q=2940
  • p=84p=84 , q=735q=735
  • p=105p=105 , q=588q=588
  • p=147p=147 , q=420q=420
  • p=420p=420 , q=147q=147
  • p=588p=588 , q=105q=105
  • p=735p=735 , q=84q=84
  • p=2940p=2940 , q=21q=21

In the third example, the integers are as follows:

  • X=21×51=10X=2^1\times5^1=10
  • Y=21×31=6Y=2^1\times3^1=6

There is no pair pp and qq that simultaneously satisfies LCM(p,q)=10\text{LCM}(p,q)=10 and GCD(p,q)=6\text{GCD}(p,q)=6 .

首页