2 条题解

  • 1
    @ 2025-12-19 21:43:23

    #include #include using namespace std;

    int main() { int n; cin >> n;

    if (n < 5) {
        cout << "empty" << endl;
        return 0;
    }
    
    // 筛素数
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (is_prime[i]) {
            for (int j = i * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    
    bool found = false;
    for (int i = 2; i <= n - 2; i++) {
        if (is_prime[i] && is_prime[i + 2]) {
            cout << i << " " << i + 2 << endl;
            found = true;
        }
    }
    
    if (!found) {
        cout << "empty" << endl;
    }
    
    return 0;
    

    }

    • 0
      @ 2026-1-15 19:44:06
      #include<bits/stdc++.h>
      bool f(int x){
      	if(x<2)
              return false;
      	for(int i=2;i*i<=x;i++)
      		if(x%i==0)
                  return false;
      	return true;
      }
      using namespace std;
      int main(){
      	int a,s=0;
          cin>>a;
      	for(int i=1;i<=a;++i)
      		if(f(i-2)&&f(i)){
                  s++;
                  cout<<i-2<<" "<<i<<endl;
              }
      	if(s==0)
              cout<<"empty";
      	return 0;
      }
      
      • 1

      信息

      ID
      6989
      时间
      1000ms
      内存
      128MiB
      难度
      1
      标签
      递交数
      14
      已通过
      5
      上传者