题解:CF2093C Simple Repetition

· · 题解

首先考虑 k=1 的情况,得到的数就是 x。所以判断 x 是否是质数即可。

然后就是 k\neq 1 的情况。对于这种情况,设 x 位数为 num,手玩一下发现得到的数是 (x \times 10^{num}+x)\times 10^{num}\dots。

所以展开可以知道就是 x \times (10^{(k-1)num}+10^{(k-2)num}+\dots),第二个数必不等于 1,所以当 x\neq 1 时,不合法;当 x=1 时,11 合法。特判即可。

#include<bits/stdc++.h>
using namespace std;
struct FSI{
    template<typename T>
    FSI& operator >> (T &res){
        res=0;T f=1;char ch=getchar();
        while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
        while (isdigit(ch)){res=res*10+ch-'0';ch=getchar();}
        res*=f;
        return *this;
    }
}scan;
int T,x,k,i;
bool isprime(int x)
{
    int i;
    if (x==1) return false;
    for (i=2;i<=sqrt(x);i++)
    {
        if (x%i==0) return false;
    }
    return true;
}
void work()
{
    scan>>x>>k;
    if (x==1&&k==2){printf("YES\n");return;}
    if (k!=1) printf("NO\n");
    else
    {
        if (isprime(x)) printf("YES\n");
        else printf("NO\n");
    }
}
int main()
{
    scan>>T;
    while (T--) work();
    return 0;
}