Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
24187 U•ェ•*✔ 【PAT】性感素数 C++ 通过 0 MS 252 KB 531 2023-07-21 17:35:07

Tests(20/20):


#include"bits/stdc++.h" using namespace std; bool check(int x){ if(x==1)return 0; for(int i=2;i*i<=x;i++){ if(x%i==0)return 0; } return 1; } int main(){ int n; cin>>n; if(check(n)){ if(check(n-6)){ cout<<"Yes"<<'\n'<<n-6; return 0; } if(check(n+6)){ cout<<"Yes"<<'\n'<<n+6; return 0; } } else{ cout<<"No"<<'\n'; while(n++){ if(check(n)&&check(n-6)&&n-6>0){ cout<<n; return 0; } if(check(n)&&check(n+6)){ cout<<n; return 0; } } } }


测评信息: