3 solutions

  • 2
    @ 2024-12-22 16:26:49
    #include<bits/stdc++.h>
    using namespace std;
    bool w(int n)
    {
    	if(n<2)
    	{
    		return 0;
    	}
    	for(int i=2;i<=n/i;i++)
    	{
    		if(n%i==0)
    		{
    			return 0;
    		}
    	}	
    	return 1;
    }
    int main()
    {
    	int n,x=0;
    	cin>>n;
    	for(int i=2;i+2<=n;i++)
    	{
    	
    		if(w(i)&&w(i+2))
    		{
    			cout<<i<<" "<<i+2<<endl;
    			x++;
    		}
    		
    	}
    		if(x==0)	
    		{
    			cout<<"empty";
    		}
    }
    • 1
      @ 2024-9-20 19:37:46
      #include<bits/stdc++.h>
      using namespace std;
      bool a(int k)
      {
      	if(k<2)
      	{
      		return false;
      	}
      	for(int i=2;i<=k/i;i++) //枚举小因子 
      	{
      		if(k%i==0) //存在小因子 
      		{
      			return false;
      		}
      	}
      	return true;
      }
      int main()
      {
      	int n;
      	cin>>n;
      	int cnt=0; 
      	for(int i=1;i+2<=n;i++)
      	{
      		if(a(i)&&a(i+2))
      		{
      			cout<<i<<" "<<i+2<<endl;	
      			cnt++;
      		}
      	}
      	if(cnt==0)
      	{
      		cout<<"empty";
      	}
      	return 0;
      }
      
      • 0
        @ 2024-8-21 15:47:12
        #include<bits/stdc++.h>
        using namespace std;
        bool w(int n)
        {
        	if(n<2)
        	{
        		return 0;
        	}
        	for(int i=2;i<=n/i;i++)
        	{
        		if(n%i==0)
        		{
        			return 0;
        		}
        	}	
        	return 1;
        }
        int main()
        {
        	int n,x=0;
        	cin>>n;
        	for(int i=2;i+2<=n;i++)
        	{
        	
        		if(w(i)&&w(i+2))
        		{
        			cout<<i<<" "<<i+2<<endl;
        			x++;
        		}
        		
        	}
        		if(x==0)	
        		{
        			cout<<"empty";
        		}
        }
        
        • 1

        Information

        ID
        931
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        1
        Tags
        (None)
        # Submissions
        48
        Accepted
        17
        Uploaded By