對稱三位數素數

/*
Jennifer
2018年2月2日16:32:52-2018年2月2日17:04:38
n%10求的是最高位,n/100求的是個位
*/
#include <iostream>
#include <cmath>
using namespace std;
bool isPrim(int n)
{
    int sqr = sqrt(n * 1.0);
    for(int i=2;i<sqr;i++)   //注意:i是從2開始
    {
        if(n%i == 0)
            return false;
    }
    return true;
}
int main()
{
    int n;
    while(cin>>n)
    {

        if(n>100 && n<1000 && n%10 == n/100 && isPrim(n))
        {
            cout<<"Yes"<<endl;
        }

        else
        {
            cout<<"No"<<endl;
        }

    }
    return 0;
}

發佈了47 篇原創文章 · 獲贊 29 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章