the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1015

this problem is relatively easy.if there must be something which need to be noticed, i think

“1 is not a prime” could be one of them.

#include<stdio.h>

bool isPrime(int n)
{
    if (n == 1)
    {
        return false;
    }
    if (n == 2)
        return true;
    else
    {
        for (int i = 2; i < n; i++)
        {
            if (n % i == 0)
            {
                return false;
            }
        }
        return true;
    }
}

int main()
{
    int n,d;
    while (scanf("%d",&n))
    {
        if (n < 0)
            break;
        scanf("%d",&d);
        int temp = n;
        int count = 0;
        while (n/d != 0)
        {
            count += n%d;
            count *= d;
            n /= d;
        }
        count += n%d;
        if (isPrime(temp)&&isPrime(count))
        {
            printf("Yes\n");
        }
        else
            printf("No\n");
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2021-06-03
  • 2020-05-19
  • 2021-07-29
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2021-08-25
  • 2021-12-19
相关资源
相似解决方案