why0???sos
  • 板块B2132 素数对
  • 楼主CoderMC
  • 当前回复7
  • 已保存回复7
  • 发布时间2025/2/7 14:10
  • 上次更新2025/2/7 16:14:02
查看原帖
why0???sos
1627604
CoderMC楼主2025/2/7 14:10
#include<bits/stdc++.h>
using namespace std;
int n,b;
bool IsPrime(int x){
    for(int i=2;i*i<=x;i++){
        if(x%i==0){
            return 0;
        }
        else{
            return 1;
        }
    }
}

int main(){
    cin>>n;
    for(int i=2;i<=n;i++){
        if(IsPrime(i)&&IsPrime(i+2)){
            b=1;
            cout<<i<<" "<<i+2<<endl;
        }
        
    }
    if(b==0){
            cout<<"empty";
        }
    return 0;
}
2025/2/7 14:10
加载中...