8639: Ironforge

内存限制:128 MB 时间限制:3 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

The subway of Ironforge can been seen as a chain of n2 vertices. In other words, for each i=1,2,3...n1, there is an edge between vertex ii and vertex i+1

There is a number ai(1in) on vertex ii and a prime number bi(1i<n) written on the edge between vertex i and vertex i+1.

You may start a trip on some vertex with an empty bag. When you are on vertex i, you can put all prime factors of ai into your bag. You can walk through an edge with prime number p written on it if and only if you already have p in your bag. You are allowed to pass each vertex and each edge multiple times.

You need to answer mm queries. In each query you are given two numbers x,y. You need to answer whether you can reach vertex y if you start your trip on vertex xx by the subway of Ironforge.

输入格式

The input consists of multiple test cases.

The first line contains an integer T (1T3) denoting the number of test cases.

For each test case, the first line contains two integers n and m (2n,m2×105), denoting the number of vertices and the number of queries.

The second line contains n integers ai (1in,1ai2×105).

The third line contains n-1 integers bi (1i<n,2bi2×105).

Following m lines describe the queries. Each line contains two integers x,y (1x,yn).

输出格式

For each query, output one line containing "Yes" if its possible to reach vertex y from vertex x and "No" otherwise.

输入样例 复制

1
5 5
7 1 6 6 14
7 2 3 2
1 2
1 4
3 5
5 1
3 1

输出样例 复制

Yes
No
Yes
Yes
Yes