19 条题解
-
2
include <bits/stdc++.h>
using namespace std;
bool zhishu(long long n) { for(long long i = 2;i<=n-1;i++){ if (n % i ==0){ return false; } } return true; } int main(){ long long n; cin >>n; if(n < 5 and n >= 0){ cout <<"empty"<<endl; return 0; } for(long long i = 2;i<=n-2;i++){ if(zhishu(i)and zhishu(i+2)){ cout <<i<<" "<<i+2<<endl; } } return 0; }
-
2
#include using namespace std; int n,cnt; bool check(int a){ for(int i=2;i*i<=a;i++){ if(a%i0)return false; } return true; } int main(){ cin>>n; for(int i=2;i<=n;i++){ if(i+2<=n&&check(i)&&check(i+2)){ cout<<i<<" "<<i+2<<endl; cnt=1; } } if(cnt0)cout<<"empty"; return 0;
-
-
-
-
-
-
-
-
-
-
-
-
-
- }***
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [ ] 2. | col1**** | col2 | col3 | | --- | --- | --- | | | | | | | | |***
-
-
-
-
-
-
-
-
1
#include<bits/stdc++.h> using namespace std; int cheak(int n){ if(n1) return 0; for(int i=2;i<n;i++){ if(n%i0){ return 0; } } return 1; } int main(){ int a[10000]={},n,cnt=0,flag=0; cin>>n; for(int i=1;i<=n;i++){ if(cheak(i)){ a[cnt]=i; cnt++; } } for(int i=1;i<cnt-1;i++){ if(a[i+1]-a[i]2){ cout<<a[i]<<" "<<a[i+1]<<endl; flag=1; } } if(flag0){ cout<<"empty"; } }
-
-2
#include<bits/stdc++.h> using namespace std; bool f(int n) { if(n<=1) return 0; for(int i=2;i<=sqrt(n);i++) if(n%i0) return false; return true; } int main() { int n,s=0; cin>>n; for(int i=2;i<=n;i++) { if(f(i)&&f(i+2)&&i+2<=n) { cout<<i<<" "<<i+2<<endl; s=1; } } if(s0) cout<<"empty"; return 0; }
-
-2
其实这题很简单,只需要埃氏筛法就行,不知为啥各位大老搞这么复杂? #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; }
-
-2
#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"; } }
-
-2
#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; }
- 1
信息
- ID
- 946
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- (无)
- 递交数
- 1174
- 已通过
- 323
- 上传者