C. Simple Repetition

time limit per test

1 second

memory limit per test

256 megabytes

Pasha loves prime numbers∗! Once again, in his attempts to find a new way to generate prime numbers, he became interested in an algorithm he found on the internet:

  • To obtain a new number y, repeat k times the decimal representation of the number x (without leading zeros).

For example, for x=52 and k=3, we get y=525252, and for x=6 and k=7, we get y=6666666.

Pasha really wants the resulting number y to be prime, but he doesn't yet know how to check the primality of numbers generated by this algorithm. Help Pasha and tell him whether y is prime!

∗An integer x is considered prime if it has exactly 2 distinct divisors: 1 and x. For example, 13 is prime because it has only 2 divisors: 1 and 13. Note that the number 1 is not prime, as it has only one divisor.

Input

Each test consists of several sets of input data. The first line contains a single integer t (1≤t≤100) --- the number of sets of input data. The following lines describe the sets of input data.

The first and only line of each data set contains two integers: x and k (1≤x≤109, 1≤k≤7).

Output

For each set of input data, output <<YES>> (without quotes) if the resulting number y will be prime, and <<NO>> otherwise.

You may output <<Yes>> and <<No>> in any case (for example, the strings <<yES>>, <<yes>>, and <<Yes>> will be recognized as positive answers).

Example

Input

Copy

复制代码

4

52 3

6 7

7 1

1 7

Output

Copy

复制代码
NO
NO
YES
NO

解题说明:此题是一道数学题,题意就是将一个数字x重复k次,判断产生的数是否是质数,直接判断即可。

cpp 复制代码
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        long long int n;
        long int l, m, h, x, s;
        l = 1;
        scanf("%lld %ld", &n, &x);
        if (x >= 2 && n != 1)
        {
            printf("NO\n");
        }
        else if (n == 1 && x != 2) 
        {
            printf("NO\n");
        }
        else if (n == 1 && x == 2)
        {
            printf("YES\n");
        }
        else
        {
            for (int i = 2; i * i <= n; i++)
            {
                if (n % i == 0) 
                {
                    printf("NO\n");
                    l = 0;
                    break;
                }
            }
            if (l)
            {
                printf("YES\n");
            }
        }
    }
    return 0;
}