25 条题解

  • -3
    @ 2023-2-4 22:12:49

    其实这题很简单,只需要埃氏筛法就行,不知为啥各位大老搞这么复杂? #include <bits/stdc++.h> using namespace std;

    bool flag[10005]; void isPrime() { memset(flag, true, sizeof(flag)); flag[0] = flag[1] = false; for (int i = 2; i <= 10000; i++) { if (flag[i]) { for (int j = 2; j <= 10000 / i; j++) { flag[i * j] = false; } } } }

    int main() { isPrime(); int x, y; cin >> x >> y; bool vis = false; for (int i = x; i <= y; i++) { if (flag[i] && flag[i+2]) { cout << i << " " << i + 2 << endl; vis = true; } } if (!vis) cout << "empty" << endl; return 0; }

    • -3
      @ 2022-10-2 22:03:35

      #include #include <math.h> #include #include <stdio.h> #include #include #include #include <string.h> #include using namespace std; #define LL long long const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; int a[N],sum[N]; bool pd(int a) { for(int i=2;i<a;i++) { if(a%i0) { return false; } } return true; } int main() { int n,h=0; cin>>n; for(int i=2;i<n;i++) { if(pd(i)&&pd(i+2)) { cout<<i<<' '<<i+2<<endl; h=1; } } if(h0) { cout<<"empty"; } }

      • -3
        @ 2022-3-8 17:07:02

        #include #include<bits/stdc++.h> using namespace std; bool ss(int x){ for(int i=2;i<x/2;i++){ if(x%i==0) return false; } return true; } int main(){ int n,i,j; bool a=true; cin>>n; for(i=3;i<=n;i+=2){ if(ss(i)&&ss(i+2)&&i+2<=n){ cout<<i<<" "<<i+2<<endl; a=false; } } if(a) cout<<"empty"; return 0; }

        • -3
          @ 2022-1-11 10:07:30
          #include<bits/stdc++.h>
          using namespace std;
          int main()
          {
              int n;
              cin >> n;
              int sum = 0;
              for(int i = 3; i + 2 <= n ; i +=2)
              {
              	int flag =1;
              	for(int j = 2; j*j <= i;j++)
              	{
              		if(i%j == 0)
              		{
              			flag = 0;
              			break;
          			}
          		}
          		if (flag == 0)
          			continue;
          		for(int j = 2 ; j*j<=i+2; j++)
          		{
          			if((i+2)%j == 0)
          			{
          				flag = 0;
          				break;
          			}
          		}
          		if(flag == 1)
          		{
          			sum++;
          			cout << i << " " << i + 2 << endl;
          		}
          	}
          if(sum == 0)
          {
          	cout <<"empty\n";
          }
          	return 0;
          }
          
          • -4
            @ 2022-1-11 10:23:31
            #include <math.h>
            #include <stack>
            #include <stdio.h>
            #include <iostream>
            #include <vector>
            #include <iomanip>
            #include <string.h>
            #include <algorithm>
            using namespace std;
            #define LL long long
            const int N = 1e5 + 10;
            const int INF = 0x3f3f3f3f;
            int main()
            {
                int n;
                cin >> n;
                int sum = 0;
                for(int i = 3 ; i + 2 <= n ; i += 2)
                {
                    int flag = 1;
                    for(int j = 2; j*j <= i ; j++)
                    {
                        if(i%j == 0)
                        {
                            flag = 0;
                            break;
                        }
                    }
                    if(flag == 0)
                    {
                        sum++;
                        cout << i << " " << i + 2 << endl;
                    }
                }
                if(sum==0)
                {
                    cout << "empty\n";
                }
                return 0;
            }```

            信息

            ID
            946
            时间
            1000ms
            内存
            128MiB
            难度
            6
            标签
            (无)
            递交数
            1414
            已通过
            383
            上传者