luogu#P2429. 制杖题

    ID: 1806 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>搜索数学洛谷原创容斥原理洛谷月赛

制杖题

Problem Description

Find the sum of all natural numbers not exceeding mm whose set of prime factors intersects the given set of primes.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers pip_i, representing the elements of the prime set.

Output Format

Output one integer, the answer modulo 376544743376544743.

2 15
3 5
60

Hint

Sample explanation: All qualifying numbers are 3,5,6,9,10,12,153, 5, 6, 9, 10, 12, 15, and their sum is 6060.

Test point ID Constraints
131 \sim 3 nm107n m \le {10}^7
454 \sim 5 n2n \le 2m109m \le {10}^9
676 \sim 7 n20n \le 20m108m \le {10}^8
8108 \sim 10 n20n \le 20m109m \le {10}^9

For the first 30%30\% of the testdata, 1n,m1 \le n, m.

For the remaining 70%70\% of the testdata, 1n201 \le n \le 201m1091 \le m \le {10}^9.

Translated by ChatGPT 5